output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include<iostream> #include<cstdio> #include<cstring> using namespace std; string s; int main(){ cin>>s; int len=s.size(); for(int i=0;i<len-1;i++){ if(s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl; return 0; } } for(int i=0;i<len-2;i++){ if(s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<endl; return 0; } } ...
### Prompt Generate a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s...
#include<cstdio> #include<cstring> using namespace std; #define MAXN 100005 char s[MAXN]; int main() { scanf("%s",s); int len=strlen(s); for(int i=0;i<=len-2;i++) { if(s[i]==s[i+2]) { printf("%d %d\n",i+1,i+3); return 0; } if(s[i]==s[i+1]) { printf("%d %d\n",i+1,i+2); return 0; } } printf(...
### Prompt In CPP, your task is to solve the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a strin...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); for(int i = 0; i < n; i++) { if(i<n-1 && s[i] == s[i+1]) { cout << i+1 << " " << i+2; return 0; } if(i<n-2 && s[i] == s[i+2]) { cout << i+1 << " " << i+3; return 0; } } cout << "-1 -1"; }
### Prompt Please formulate a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=(a);i<(b);++i) int main() { string S; cin >> S; int n = S.size(); if (n == 2 && S[0] == S[1]) { puts("1 2"); exit(0); } for_(i,0,n-2) { if (S[i] == S[i+1] || S[i] == S[i+2]) { cout << i+1 << " " << i + 3 << endl; exit(0)...
### Prompt Please formulate a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char s[100100]; int main(){ scanf("%s",s+1); int n=strlen(s+1); for(int i=1;i<=n;i++){ if(s[i-1]==s[i]){ cout<<i-1<<" "<<i; return 0; } else if(s[i]==s[i-2]){ cout<<i-2<<" "<<i; return 0; } else if(i==n){ cout<<"-1 -1...
### Prompt Develop a solution in cpp to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; string s; int main() { cin >> s; for(int i = 1; i<s.size(); i++) if(s[i] == s[i - 1]) { cout << i << " " << i + 1 << endl; return 0; } for(int i = 2; i < s.size(); i++) if(s[i] == s[i - 2]) { cout << i - 1 << " " << i + 1 << endl; return 0; } cout << ...
### Prompt Please provide a cpp coded solution to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; for (int i = 0; i + 1 < s.size(); i++) { if (s[i] == s[i + 1]) { cout << i + 1 << " " << i + 2 << endl; return 0; } if (i && s[i - 1] == s[i + 1]) { cout << ...
### Prompt Please create a solution in Cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include "bits/stdc++.h" using namespace std; int main() { string S; cin >> S; for (int i = 0; i < S.size() - 1; i++) { if (S[i] == S[i + 1]) { cout << i + 1 << " " << i + 2; goto END; } } for (int i = 0; i < S.size() - 2; i++) { if (S[i] == S[i + 2]) { cout << i + 1 << " " << i + 3; goto END; ...
### Prompt Develop a solution in cpp to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<cstdio> #include<cstring> const int N=1e5+50; char s[N]; int len,x,y,ans; int main(){ scanf("%s",s); len=strlen(s); for(int i=0;i<len;i++){ if(s[i]==s[i+1]){printf("%d %d\n",i+1,i+2);return 0;} else if(s[i]==s[i+2]){printf("%d %d\n",i+1,i+3);return 0;} } printf("-1 -1\n"); }
### Prompt Please formulate a CPP solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int n=s.length(); for(int i=0;i<n-1;i++){ if(s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl; return 0; } if(i!=n-3 && s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<endl; return 0; } } cout<<-1<<" "<<-1<<e...
### Prompt Please create a solution in cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<iostream> #include<cstring> using namespace std; int main(){ string s; cin>>s; int l=s.size(); int i=0; for(i=0;i<l;i++){ if(s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl; return 0; }else if(s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<endl; return 0; } } cout<<"-1"<<" "<<"-1"<<endl; return 0; }
### Prompt Construct a cpp code solution to the problem outlined: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a str...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string s; cin>>s; for(int i=0;i<s.size()-1;i++){ if(i!=s.size()-2){ if(s[i]==s[i+2]){ cout<<i+1<<' '<<i+3<<endl; return 0; } } if(s[i]==s[i+1]){ cout<<i+1<<' '<<i+2<<endl; return 0; } } cout<<-1<<' '<<-1<<e...
### Prompt Please create a solution in Cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(false); string s;cin>>s; int len=s.length(); int l=-1,r=-1; //bool flag=false; for(int i=0;i<len-1;i++){ if(s[i]==s[i+1]) {l=i+1;r=l+1;} } for(int i=0;i<len-2;i++){ if(s[i]==...
### Prompt Develop a solution in cpp to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> using namespace std; char s[100005]; int main() { scanf("%s",s); int len=strlen(s); if(len==2) { if(s[0]==s[1]) printf("1 2\n"); else printf("-1 -1\n"); return 0; } for(int i=0;i<len-2;i++) { if(s[i]==s[i+1]||s[i]==s[i+2]) { pri...
### Prompt Your task is to create a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are gi...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int N = s.size(); for (int i = 0; i < N-1;i++){ if(s[i]==s[i+1]) { cout << i +1<< ' '<<i + 2 << endl; return 0; } } for (int i = 0; i < N - 2;i++){ if(s[i]==s[i+2]){ cout << i+1 << ' '<<i + 3 << end...
### Prompt Develop a solution in Cpp to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; for(int i=0;i<s.size()-1;i++){ if(s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl; return 0; } } for(int i=0;i<s.size()-2;i++){ if(s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<endl; return 0; } } cout<<-1<<" "<<-1<<endl; return 0; }
### Prompt In CPP, your task is to solve the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a strin...
#include <bits/stdc++.h> using namespace std; char s[100010]; int main() { int i,l,ch,left=-1,right=-1; scanf("%s",s+1); l=strlen(s+1); for(i=1;i<l;i++) if(s[i]==s[i+1]){ left=i;right=i+1; break; } if(left==-1) for(i=1;i<l-1;i++) if(s[i]==s[i+2]){ left=i;right=i+2; break; } printf("%d %d\n",...
### Prompt Your task is to create a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are gi...
#include <bits/stdc++.h> using namespace std; char s[500003]; int main() { scanf("%s",s); int a; a=strlen(s); for(int i=0;i<a-1;i++) { if(s[i]==s[i+1]){cout<<i+1<<" "<<i+2<<endl;return 0;} else if(i+2<a&&s[i]==s[i+2]){cout<<i+1<<" "<<i+3<<endl;return 0;} //else if(i+3<a&&s[i]==s[i+3]...
### Prompt Please formulate a CPP solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string s; cin >> s; bool isE=false; for(int i = 1;i < s.size();i ++){ if(s[i]==s[i-1]) {cout << i << " " << i+1 << endl;isE=1;break;} if(i-1&&s[i]==s[i-2]) {cout << i-1 << " " << i+1 << endl;isE=1;break;} ...
### Prompt Your challenge is to write a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <iostream> using namespace std; int main(){ string s; cin >> s; //aa axa for(char c = 'a'; c <= 'z'; c++){ for(size_t i = 0; i < s.size() - 1; i++){ if(s[i] == s[i + 1]){ cout << i + 1 << ' ' << i + 2 << endl; return 0; }else if(i + 2 < s.size() && s[i] == s[i + 2]){ cout << i + 1 << '...
### Prompt Please create a solution in Cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int n = s.length(); for (int i=0; i<n-1; i++) { if (s[i] == s[i+1]) { cout<<i+1<<" "<<i+2<<endl; return 0; } if (i+2 < n && s[i] == s[i+2]) { cout<<i+1<<" "<<i+3<<endl; return 0; } } cout<<"...
### Prompt Please create a solution in CPP to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) { cout << i + 1 << " " << i + 2 << endl; return 0; } } for (int i = 0; i < n - 2; i++) { if (s[i] == s[i + 2]) { cout << i + 1 << " " << i + 3 ...
### Prompt Your task is to create a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are gi...
#include <bits/stdc++.h> using namespace std; char s[100005]; int f[27]; int main () { scanf("%s", s); int n=strlen(s); for (int i=0; i<n-1; i++) { if (s[i]==s[i+1]) { printf("%d %d\n", i+1, i+2); return 0; } if (s[i]==s[i+2]) { printf("%d %d\n", i+1, i+3); return 0; } } printf("-1 -1\n"); ret...
### Prompt Develop a solution in CPP to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; string a; int main() { cin>>a; for(int i=1;i<a.size();i++) if(a[i]==a[i-1]) { cout<<i<<" "<<i+1<<endl; return 0; } for(int i=2;i<a.size();i++) if(a[i]==a[i-2]) { cout<<i-1<<" "<<i+1<<endl; return 0; } cout<<-1<<" "<<-1<<endl; }
### Prompt Your challenge is to write a CPP solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; for (int a = 0; a + 1 < S.length(); a++) { if (S[a] == S[a + 1]) { printf("%d %d\n", a + 1, a + 2); return 0; } } for (int a = 0; a + 2 < S.length(); a++) { if (S[a] == S[a + 2]) { printf("%d %d\n"...
### Prompt Your task is to create a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are gi...
#include <iostream> #include <algorithm> #include <string> using namespace std; int main() { int a, b, len; string s; cin >> s; len = s.length(); a = b = -2; for(int i=1;i<len;i++) { if(s[i-1] == s[i]) { a = i-1; b = i; break; } if(i >= 2 && s[i-2] == s[i]) { a = i - 2; b = i; break; } } a+...
### Prompt Develop a solution in cpp to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; #define ll long long char a[100010]; int main(){ cin>>a+1; int n=strlen(a+1); for(int i=1;i<n;i++){ if(a[i]==a[i+1]) return cout<<i<<' '<<i+1<<'\n',0; } for(int i=1;i+2<=n;i++){ if(a[i]==a[i+2]) return cout<<i<<' '<<i+2<<'\n',0; } cout<<-1<<' '<<-1<<'\n'; }
### Prompt Please provide a Cpp coded solution to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long ll; typedef pair<ll,ll> P; signed main(){ string s; cin >> s; for(int i=0;i<s.size()-1;i++){ if(s[i]==s[i+1]){ cout << i+1<<" "<<i+2<<endl; return 0; }else if(i!=0&&s[i-1]==s[i+1]){ cout << i<<...
### Prompt In cpp, your task is to solve the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a strin...
#include<cstdio> #include<cstring> #define MAXN 200000 char str[MAXN+5]; int main(){ scanf("%s",str+1); int len=strlen(str+1); for(int i=1;i<=len;i++){ if(str[i]==str[i+1]){ printf("%d %d",i,i+1); return 0; } if(str[i]==str[i+2]){ printf("%d %d",...
### Prompt Please provide a Cpp coded solution to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (i + 1 < s.length() && s[i] == s[i+1]) { cout << i + 1 << ' ' << i + 2 << '\n'; return 0; } if (i + 2 < s.length() && s[i] == s[i+2]) { cout << i + 1 << ' ' << i + 3 << '\n';...
### Prompt Create a solution in Cpp for the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string...
#include <iostream> #include <cstdio> using namespace std; int n; string a; int main() { int i; cin >> a; a = ' ' + a; for (i = 1; i < a.size() - 1; i++) { if (a[i] == a[i + 1]) { printf("%d %d", i, i + 1); return 0; } if (i + 2 < a.size() && a[i] == a[i + 2]) { printf("%d %d", i, i + 2); return ...
### Prompt Create a solution in cpp for the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string...
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+7; char s[maxn]; int main() { scanf("%s",s+1); int n=strlen(s+1); for(int i=1;i<=n;i++) { if(i<n&&s[i]==s[i+1]) { printf("%d %d\n",i,i+1); return 0; } if(i<n-1&&s[i]==s[i+2]) { printf("%d %d\n",i,i+2); return 0; } } printf("-1...
### Prompt Your task is to create a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are gi...
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=(a);i<(b);++i) int main() { string S; cin >> S; int n = S.size(); for_(x,1,3) for_(i,0,n-x) { if (S[i] == S[i + x]) { cout << i+1 << " " << i+x+1 << endl; exit(0); } } puts("-1 -1"); }
### Prompt Construct a CPP code solution to the problem outlined: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a str...
#include<iostream> #include<cstring> using namespace std; int main() { string s; cin>>s; int i=0,j=0; for(int l=0;l<s.length()-1;l++) { if(s[l]==s[l+1]) { i=l+1; j=l+2; } } for(int p=0;p<s.length()-2;p++) { if(s[p]==s[p+2]) { i=p+1; j=p+3; } } if(i==0 && j==0) { i=-1; j=-1; } co...
### Prompt Please create a solution in cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <iostream> using namespace std; int main() { string s; cin >> s; int N = s.length(); for (int i = 0; i < N - 1; i++) { if (s[i] == s[i + 1]) { cout << i + 1 << " " << i + 2 << endl; return 0; } if (i + 2 < N && s[i] == s[i + 2]) { cout << i + 1 << " " << i + 3 << endl; return 0; } } c...
### Prompt Your challenge is to write a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <cstdio> char s[100100]; int main() { scanf("%s", s+1); for(int i = 1; s[i]; i ++ ) if(s[i] == s[i+1] || s[i] == s[i+2]) return printf("%d %d\n", i, s[i+2]?i+2:i+1), 0; puts("-1 -1"); }
### Prompt Your challenge is to write a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; signed main() { string s; cin >> s; s += '?'; for (int i = 1; i < s.length()-1; i++) { if (s[i-1] == s[i]) { cout << i << ' ' << i+1; return 0; } if (s[i-1] == s[i+1]) { cout << i << ' ' << i+2; re...
### Prompt Your challenge is to write a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; int sz = s.size(); int a = -1, b = -1; for (int i = 1; i < sz; i++) { if (s[i] == s[i - 1]) { a = i, b = i + 1; } else if (i + 1 < sz && s[i - 1] == s[i + 1]) { a = i, b = i + 2; } } cout << a <<...
### Prompt Please formulate a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; char s[100020]; int main() { scanf("%s", s); for (int i = 0; s[i]; i++) { if (s[i] == s[i + 1]) { printf("%d %d\n", i + 1, i + 2); return 0; } if (s[i] == s[i + 2]) { printf("%d %d\n", i + 1, i + 3); return 0; } } printf("-1 -1\n"); return 0; }
### Prompt Create a solution in CPP for the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string...
#include<iostream> using namespace std; int main() { string s; cin>>s; for(int i=1;i<s.length();i++) { if(s[i]==s[i-1]) { cout<<i<<" "<<i+1<<endl; return 0; } } for(int i=2;i<=s.length();i++) { if(s[i]==s[i-2]) { cout<<i-1<<" "<<i+1<<endl; return 0; } } cout<<-1<<" "<<-1<<endl; return ...
### Prompt Create a solution in Cpp for the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string...
#include<cstdio> #include<cstring> using namespace std; #define MAXN 1000005 char s[MAXN]; int main() { scanf("%s",s); int len=strlen(s); for(int i=0;i<=len-1;i++) { if(s[i]==s[i+1]) { printf("%d %d\n",i+1,i+2); return 0; } if(s[i]==s[i+2]) { printf("%d %d\n",i+1,i+3); return 0; } } printf...
### Prompt Please formulate a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { string s; cin >> s; ll n = s.size(); for (ll i = 1; i < n; ++i) { if (s[i - 1] == s[i]) { cout << i << " " << i + 1 << endl; return 0; } } for (ll i = 2; i < n; ++i) { if (s[i - 2] == s[i]) { cout << i - 1 << " " << i ...
### Prompt Your challenge is to write a CPP solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include "bits/stdc++.h" using namespace std; int main(){ string s; cin>>s; for(int i=0;i<s.size()-2;i++){ if(s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl; return 0; } if(s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<endl; return 0; } } if(s[s.size()-2]==s[s.size()-1]){ cout<<s.size()-1<<" "<<s.size()...
### Prompt Your challenge is to write a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include <bits/stdc++.h> using namespace std; int main(void){ string s; cin>>s; for(int i=0;i<s.size()-1;i++){ if(s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl; return 0; } } for(int i=0;i<s.size()-2;i++){ if(s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<...
### Prompt Please create a solution in CPP to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <iostream> using namespace std; int main(){ string s; cin >> s; if(s.size()==2&&s[0]==s[1]){ cout << "1 2"; return 0; } for(int i = 0;i < s.size() - 2;i++){ int j = i; if(s[j]==s[j+1]||s[j]==s[j+2]||s[j+1]==s[j+2]){ cout << j+1 << " " << j+3; ...
### Prompt Please provide a Cpp coded solution to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include<bits/stdc++.h> using namespace std; string s; int main() { cin >> s; for(int i = 1; i<s.size(); i++) if(s[i] == s[i - 1]) { cout << i << " " << i + 1 << endl; return 0; } for(int i = 2; i < s.size(); i++) if(s[i] == s[i - 2]) { cout << i - 1 << " " << i + 1 << endl; return 0; } cout << ...
### Prompt Construct a Cpp code solution to the problem outlined: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a str...
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; int n = s.length(); for(int i = 0; i + 2 < n; i++) { if(s[i] == s[i+1] || s[i] == s[i+2]) return cout << i + 1 << " " << i + 3 << endl, 0; } if(n >= 2 && (s[n-1] == s[n-2])) return cout << n - 1 << " " << n << e...
### Prompt Please formulate a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int n=s.size(); for(int i=0;i<n-1;i++){ if(s[i]==s[i+1]){ cout << i+1 << " " << i+2 << endl; return 0; } } for(int i=0;i<n-2;i++){ if(s[i]==s[i+2]){ cout << i+1 << " " << i+3 << endl; return 0; ...
### Prompt Create a solution in CPP for the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string...
#include<cstdio> #include<iostream> using namespace std; string s; int main() { cin>>s; for(int i=1;i<s.size();i++) if(s[i-1]==s[i]) { printf("%d %d",i,i+1); return 0; } for(int i=1;i<s.size()-1;i++) if(s[i-1]==s[i+1]) { printf("%d %d",i,...
### Prompt Construct a cpp code solution to the problem outlined: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a str...
#include<bits/stdc++.h> using namespace std; char s[100100]; int main() { scanf("%s",s); if(strlen(s)==2) { if(s[0]==s[1]) { printf("1 2\n"); return 0; } } else for(int i=2;s[i];i++) { if(s[i]==s[i-1]||s[i]==s[i-2]||s[i-1]==s[i-2]) { printf("%d %d\n",i-2+1,i+1); return 0; } } ...
### Prompt Please provide a CPP coded solution to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include<stdio.h> int main(){ char s[111111]; int i,a=-1,b=-1; for(i=0;i<111111;i++) s[i]='\0'; scanf("%s",s); if(s[0]==s[1]){ a=1; b=2; } for(i=2;s[i]!='\0';i++){ if(s[i]==s[i-1]){ a=i; b=i+1; } if(s[i]==s[i-2]){ a=i-1; b=i+1; } } printf("%d %d\n",a,b); return 0; }
### Prompt In Cpp, your task is to solve the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a strin...
#include<cstdio> #include<cstring> #include<iostream> using namespace std; char a[100000+5]; int alen; int main() { scanf("%s",a); alen=strlen(a); for(int i=0;i<alen-1;i++) if(a[i]==a[i+1]) { printf("%d %d\n",i+1,i+2); return 0; } for(int i=0;i<alen-2;i++) if(a[i]==a[i+1]||a[i]==a[i+2]||a[i+1]==a[i+2]...
### Prompt Construct a CPP code solution to the problem outlined: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a str...
#include<bits/stdc++.h> using namespace std; const int MAXN=100005; char s[MAXN]; int main(){ scanf("%s",s); int len=strlen(s); int a=-1,b=-1; for(int i=1;i<len;i++){ if(s[i]==s[i-1]){ a=i-1,b=i; break; } } if(a==-1){ for(int i=2;i<len;i++){ if(s[i]==s[i-2]){ a=i-2,b=i; break; } } } ...
### Prompt In Cpp, your task is to solve the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a strin...
#include<bits/stdc++.h> using namespace std; int main(){ string s;cin>>s; for(int i=0;i<26;i++){ char a='a'+i; int c=-10; for(int j=0;j<s.size();j++){ if(s[j]==a){ if(j-c<=2){ cout<<c+1<<" "<<j+1<<endl; return 0; } else c=j; } } } cout<<-1<...
### Prompt Your task is to create a cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are gi...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int n = s.length(); for (int i=0; i<n-1; i++) { if (s[i] == s[i+1]) { cout<<i+1<<" "<<i+2<<endl; return 0; } if (i == n-2) { break; } if (s[i] == s[i+2]) { cout<<i+1<<" "<<i+3<<endl; ...
### Prompt Create a solution in Cpp for the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string...
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; for(int i=0;i<s.size()-1;i++) { if(s[i]==s[i+1]) { cout<<i+1<<" "<<i+2<<endl; return 0; } if(i+2<s.size()) { if(s[i]==s[i+2]) { cout<<i+1<<" "<<i+3<<endl; return 0; } } } cout<...
### Prompt Please provide a cpp coded solution to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include<iostream> using namespace std; bool vis[50]; int main() { string s; cin>>s; for(int i=0;i<s.length();++i){ if(i+1<s.length()&&s[i]==s[i+1]){ cout<<i+1<<" "<<i+2<<endl;return 0; } if(i+2<s.length()&&s[i]==s[i+2]){ cout<<i+1<<" "<<i+3<<endl;return 0; } ...
### Prompt Your challenge is to write a CPP solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You ar...
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; char s[N]; int main() { scanf("%s",s+1); int len=strlen(s+1); if(len==2&&s[1]==s[2]){ printf("1 2\n"); return 0; } int l=-1,r=-1; for(int i=1;i<len-1;i++){ if(s[i]==s[i+1]||s[i]==s[i+2]||s[i+1]==s[i+2]){ ...
### Prompt Please create a solution in cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include<bits/stdc++.h> using namespace std; int main(){ int n; string s; cin>>s; n=s.size(); for(int i=1;i<n;++i){ if(i>1&&s[i-2]==s[i])cout<<i-1<<" "<<i+1,exit(0); else if(s[i-1]==s[i])cout<<i<<" "<<i+1,exit(0); } cout<<"-1 -1"; }
### Prompt In cpp, your task is to solve the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a strin...
#include <iostream> using namespace std; int main(){ string s;cin>>s; if(s.size()==2&&s[0]==s[1]){ cout << 1 << " " << 2 << endl; return 0; } for(int i = 0; s.size() > i+2; i++){ if(s[i]==s[i+1] || s[i]==s[i+2] || s[i+1]==s[i+2]){ cout << i+1 << " " << i+3 << endl; return 0; } } ...
### Prompt Please formulate a Cpp solution to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; int main(){ string a; cin >> a; int n = a.size(); for(int i = 0;i < n-1;i++){ if(a[i] == a[i+1]){ i++; cout << i << " " << i+1 << endl; return 0; } if(i != n-2 && a[i] == a[i+2]){ i++; cout << i << " " << i+2 << endl; ...
### Prompt Please create a solution in Cpp to the following problem: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; for(int i=0; i<s.size()-2; i++){ if(s[i] == s[i+1] || s[i+2] == s[i+1] || s[i] == s[i+2]){ cout<<i+1<<" "<<i+3<<endl; return 0; } } if(s.size() == 2 && s[0] == s[1]){ cout<<1<<" "<<2<<endl; ...
### Prompt Develop a solution in cpp to the problem described below: Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a ...
#include <string> #include <iostream> using namespace std; /* <expr> ::= <term> [ ('+'|'-') <term> ]* <term> ::= <factor> [ ('*'|'/') <factor> ]* <factor> ::= <number> | '(' <expr> ')' <number> :== 1?????\????????°??? */ int expr(string& s, int& i); int term(string& s, int& i); int factor(string& s, int& ...
### Prompt Generate a Cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, subtr...
#include <iostream> #include <string> #include <vector> using namespace std; int num(string&, int&); int fact(string&, int&); int mul(string&, int&); int expr(string&, int&); int num(string &s, int &k) { int ret = 0; while ('0' <= s[k] && s[k] <= '9') { ret *= 10; ret += s[k] - '0'; k ...
### Prompt Your challenge is to write a CPP solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include <iostream> #include <sstream> using namespace std; int pos; string str; int str_to_int(string str) { if (str == "") return 0; int ret = 0; stringstream ss; ss << str; ss >> ret; return ret; } int keisan(); int kou(); int number(); int keisan() { int left = kou(); while (str[pos] != '=' && str[...
### Prompt Your challenge is to write a cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include<bits/stdc++.h> using namespace std; #define int long long int expression(string,int&); int term(string,int&); int factor(string,int&); int number(string,int&); bool f; int expression(string s,int& p){ int res=term(s,p); while(p<(int)s.size()){ if(s[p]=='+'){ p++; res+=term(s,p); con...
### Prompt Construct a cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include <string> #include <cctype> #include <iostream> using namespace std; typedef string::const_iterator State; class ParseError{}; int number(State&); int term(State&); int expression(State&); int factor(State&); int number(State& begin){ int ret = 0; while(isdigit(*begin)){ ret*=10; ret+=*begin-'0'; ...
### Prompt Create a solution in CPP for the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, sub...
#include <iostream> #include <vector> #include <sstream> #include <cctype> using namespace std; typedef string::const_iterator State; int factor(State &begin); int number(State &begin) { int ret = 0; while(isdigit(*begin)) { ret *= 10; ret += *begin - '0'; begin++; } return ret; } int term(State &begin)...
### Prompt Please provide a Cpp coded solution to the problem described below: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include <cstdio> #include <string> #include <algorithm> #include <iostream> using namespace std; typedef string::iterator State; bool isdigit(State& pos); int number(State& pos); int factor(State& pos); int expression(State& pos); int term(State& pos); bool isdigit(State& pos) { if('0'<=*pos&&*pos<='9')return true;...
### Prompt Create a solution in Cpp for the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, sub...
#include<iostream> #include<string> #include<map> using namespace std; #define ans pair<int, int> ans equation(string s, int p = 0); ans factor(string s, int p = 0); ans term(string s, int p = 0); int main(){ int n; cin >>n; while(n--){ string s; cin >>s; ans r = equation(s); cout <<r.first<<endl;...
### Prompt Develop a solution in CPP to the problem described below: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include<iostream> #include<string> #include<cmath> using namespace std; void select_cal(char c, int *tmp, int val){ if(c == '+') *tmp += val; else if(c == '-') *tmp -= val; else if(c == '*') *tmp = floor(*tmp * val); else if(c == '/' && val != 0) *tmp = floor(*tmp / val); } int calculation(string str, int len,...
### Prompt In cpp, your task is to solve the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, su...
#include<iostream> #include<string> #include<ctype.h> std::string s; std::string::iterator it; int term(); int fact(); // 計算 int expr() { int p = term(); // + or - while( *it == '+' || *it == '-' ){ if( *it == '+' ){ it++; int q = term(); p += q; } else{ it++; int q = term(); p -= q;...
### Prompt Construct a Cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include <bits/stdc++.h> using namespace std; int p; string s; int number(); int factor(); int term(); int expression(){ int num=term(); while(s.size()>p){ if(s[p]=='+'){ p++; num+=term(); }else if(s[p]=='-'){ p++; num-=term(); }else{ ...
### Prompt Construct a Cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include<string> #include<cstdlib> #include<iostream> using namespace std; int prior[128]; int parse(string s) { if(s[0]=='(' && s[s.length()-1]==')'){ bool f=true; for(int i=1,d=1;i<s.length()-1;i++){ if (s[i]=='(') d++; else if(s[i]==')') d--; if(d==0){ f=false; break; } } if(f) return parse(...
### Prompt Please create a solution in CPP to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <string> #include <iostream> #include <cassert> #include <cctype> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) string S = "3*(12+3)"; size_t cur = 0; int expression(); int digit() { assert(isdigit(S[cur])); int n = S[cur] - '0'; cur++; return n; } int nu...
### Prompt Please create a solution in CPP to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <iostream> #include <string> #include <cctype> using namespace std; typedef string::const_iterator State; int expression(State&); int term(State&); int number(State&); int factor(State&); int expression(State &begin){ int ret = term(begin); for(;;){ if(*begin == '+'){ ++begin; ret += term(begin); ...
### Prompt Construct a cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include <cstdio> #include <cctype> using namespace std; char s[111]; int cur,len; int shiki(); int kazu() { if( s[cur] == '(' ) { cur += 1; int s = shiki(); cur += 1; return s; } else { int a = s[cur]-'0'; cur += 1; while( isdigit(s[cur]) ) { a *= 10; a += s[cur]-'0'; ...
### Prompt Please create a solution in CPP to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <stdio.h> #include <vector> #include <iostream> #include <math.h> #include <algorithm> #include <cstring> #include <string> using namespace std; using ll = long long; string str; int id; int expr(); int number(){ int res = 0; for (; isdigit(str[id]); id++) { res *= 10; res += str[id] - '0'; } ...
### Prompt Your task is to create a cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, a...
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() #define LL long long using namespace std; typedef string::const_iterator State; class ParseError{}; int factor(State &begin); int number(State &begin){ int ret=0; while(isdigit(*begin)){ ret*=1...
### Prompt Please create a solution in CPP to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <iostream> #include <string> #include <algorithm> #include <cctype> using namespace std; int expression(void); string str; int pos; int factor(void){ int num = 0; if( isdigit( str[pos] ) ){ // '0' <= str[pos] && str[pos] <= '9' while( isdigit( str[pos] ) ){ num *= 10; num += str[pos] ...
### Prompt Create a solution in cpp for the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, sub...
#include <iostream> #include <cctype> #include<cassert> using namespace std; size_t cur=0; string S; int digit(){ assert(isdigit(S[cur])); int n=S[cur]-'0'; cur=cur+1; return n; } int number(){ int n=digit(); while(cur<S.size() && isdigit(S[cur])){ n=n*10+digit(); } return n; } int expression(); int factor(...
### Prompt In Cpp, your task is to solve the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, su...
#include<bits/stdc++.h> using namespace std; typedef string::const_iterator State; class ParseError{}; int expr(State& begin); int term(State& begin); int number(State& begin); int fact(State& begin); int number(State& begin){ int res = 0; while(isdigit(*begin)){ res *= 10; res += *begin - '0'...
### Prompt Please formulate a cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <iostream> #include <string> #include <cstring> #include <cctype> using namespace std; typedef string::iterator si; int expr(si& cur, si end); int num(si& cur, si end){ int ans = 0; while(cur != end && isdigit(*cur)){ ans *= 10; ans += *cur-'0'; cur++; } return ans; ...
### Prompt Develop a solution in CPP to the problem described below: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <iostream> #include <cmath> #include <vector> #include <cctype> #include <algorithm> using namespace std; int expr(); int term(); int fact(); char *p; char inp[101]; int main(){ int n; cin >> n; cin.ignore(); while (n--){ cin.getline(inp, sizeof(inp)); p = inp; cout << expr() << endl; ...
### Prompt Please provide a Cpp coded solution to the problem described below: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include <bits/stdc++.h> using namespace std; int exp(string&, int&); int term(string&, int&); int factor(string&, int&); int exp(string& str, int& p){ int res = term(str, p); while(str[p] == '+' || str[p] == '-'){ if(str[p] == '+'){ p++; res += term(str, p); }else{ p++; res -= ter...
### Prompt Your challenge is to write a cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cctype> #include <cstdio> using namespace std; typedef long long ll; typedef string::const_iterator State; #define rep(i,n) for(int i=0;i<(n);i++) class Parser{ public: int expression(State &begin){ int ret = term(begin); for(;...
### Prompt Create a solution in cpp for the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, sub...
#include <iostream> #include <string> using namespace std; int calc1(); int calc2(); int calc3(); int p; string eq; int calc1() { int a = calc2(); while (eq[p]=='+' || eq[p]=='-') { if (eq[p]=='+') { p++; a += calc2(); } else if (eq[p]=='-') { p++; a -= calc2(); } } return...
### Prompt Please create a solution in cpp to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include<iostream> #include<string> using namespace std; int exp(); int term(); int factor(); string str; int p; int factor(){ int val=0; while(str[p]>='0' && str[p]<='9'){ val*=10; val+=str[p]-'0'; p++; } if(val!=0) return val; else if(str[p]=='('){ p++; val=exp(); } if(str[p]==')...
### Prompt Please formulate a CPP solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <cmath> #include <cassert> #include <iostream> using namespace std; string S; size_t cur = 0; int digit() { int n; assert(isdigit(S[cur])); n = S[cur] -'0'; ++cur; return n; } int number() { int n = digit(); while (cur < S.size() && isdigit(S[cur])) { n = n*10 + digit(); } return n; } int expre...
### Prompt Your task is to create a CPP solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, a...
#include <stdio.h> #include <assert.h> char buf[128]; int pos; #define NOW (buf[pos]) bool isdigit(char c) { return ('0' <= c && c <= '9'); } int digit() { if ( !isdigit(NOW) ) { fprintf(stderr, "%c: ", NOW); assert( isdigit(NOW) ); } int ret = NOW - '0'; pos++; return ret; } int number() { int ret = di...
### Prompt Your challenge is to write a Cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include <iostream> #include <string> using namespace std; typedef pair<int, int> result; #define value first #define p second result equation(const string &s, int p = 0); result factor(const string &s, int p = 0); result term(const string &s, int p = 0); result equation(const string &s, int p) { result r = factor(...
### Prompt Construct a cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include <iostream> #include <cassert> #include <cctype> using namespace std; string S; size_t cur = 0; int term(); int factor(); int expression(); int digit(){ assert(isdigit(S[cur])); int n = S[cur] - '0'; cur = cur + 1; return n; } int number(){ int n = digit(); while(cur<S.size() && isdigit(S[cur])) n = n...
### Prompt Construct a cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include <bits/stdc++.h> #define endl '\n' using namespace std; int expr(string& s, int& i); int term(string& s, int& i); int factor(string& s, int& i); int number(string& s, int& i); int expr(string& s, int& i) { int val = term(s, i); while (s[i] == '+' || s[i] == '-') { char op = s[i]; ++i; ...
### Prompt Construct a CPP code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...
#include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; int expression(); int term(); int factor(); int number(); int now; string s; int expression(){ int res=term(); while(true){ if(s[now]=='+')now++,res+=term(); else if(s[now]=='-')now++,res-=t...
### Prompt Generate a cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, subtr...
#include <iostream> #include <string> #include <cctype> #include <cassert> using namespace std; string Str; unsigned int cur = 0; int digit(); int number(); int term(); int facter(); int expression(); int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cur = 0; cin >> Str; ...
### Prompt In CPP, your task is to solve the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, su...
#include <iostream> using namespace std; int cal(string&); int expression(string&, int&); int kou(string&, int&); int num(string&, int&); int cal(string& s) { int pos = 0; return expression(s, pos); } int expression(string& s, int& pos) { int left = kou(s, pos); while (1) { char op = s[pos++]; if (op == '+')...
### Prompt Your challenge is to write a Cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represent...
#include <bits/stdc++.h> using namespace std; typedef string::const_iterator State; class ParseError {}; struct Parser { int number(State &begin) { int ret = 0; while(isdigit(*begin)) { ret *= 10; ret += *begin - '0'; begin++; } return ret; } int factor(State &begin) ...
### Prompt Your task is to create a Cpp solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, a...
#include <iostream> #include <cctype> #include <cassert> using namespace std; string S; int cur; int expression(); char readerchar() { assert(cur < S.size()); char ret = S[cur]; cur += 1; return ret; } char peek() { assert(cur < S.size()); return S[cur]; } int digit() { assert(isdigit(peek(...
### Prompt Develop a solution in cpp to the problem described below: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, additio...
#include <iostream> #include <string> #include <cctype> using namespace std; typedef string::const_iterator Iter; int express(Iter &p); int term(Iter &p); int factor(Iter &p); int number(Iter &p); int express(Iter &p) { int r = term(p); for(;;) { if(*p == '+') { p++; int rs = term(p); r += rs; } el...
### Prompt Your task is to create a CPP solution to the following problem: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, a...
#include "bits/stdc++.h" #define int long long #define range(i, a, b) for(int i = a; i < b; i++) #define rep(i, a) range(i, 0, a) #define all(a) (a).begin(),(a).end() using namespace std; const int MOD = 1e9 + 7, INF = 1e17; using vi = vector <int>; using vvi = vector <vi>; //g++ -std==c++14 int expr(const char **); ...
### Prompt Construct a Cpp code solution to the problem outlined: Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, ...