#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
char c;
long long int n,m;
cin>>t;
bool f;
for(int g=0;g<t;g++)
{
cin>>s;
string a,b;
f=true;
for(int i=0;i<s.length();i++)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='%') c=s[i],f=false;
else if(s[i]>='0'&&s[i]<='9')
{
if(f)a+=s[i];
else b+=s[i];
}
}
stringstream ss(a);ss>>n;
stringstream s2(b);s2>>m;
if(c=='+') cout<<n+m<<endl;
else if(c=='-') cout<<n-m<<endl;
else if(c=='*') cout<<n*m<<endl;
else if(c=='/') cout<<n/m<<endl;
else cout<<n%m<<endl;
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
char c;
long long int n,m;
cin>>t;
bool f;
for(int g=0;g<t;g++)
{
cin>>s;
string a,b;
f=true;
for(int i=0;i<s.length();i++)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='%') c=s[i],f=false;
else if(s[i]>='0'&&s[i]<='9')
{
if(f)a+=s[i];
else b+=s[i];
}
}
stringstream ss(a);ss>>n;
stringstream s2(b);s2>>m;
if(c=='+') cout<<n+m<<endl;
else if(c=='-') cout<<n-m<<endl;
else if(c=='*') cout<<n*m<<endl;
else if(c=='/') cout<<n/m<<endl;
else cout<<n%m<<endl;
}
}
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv){ cin.tie(0); ios::sync_with_stdio(false); string a; int b,c,d,f; cin>>c; getline(cin,a); while(c--){ b=0; d=0; getline(cin,a); for(int e=0;e<a.size()+1;e++){ if(a[e]>='0'&&a[e]<='9') d=d*10+int(a[e])-48; else if(a[e]=='+'||a[e]=='-'||a[e]=='*'||a[e]=='/'||a[e]=='%'){ b=b+d; d=0; if(a[e]=='+') f=1; else if(a[e]=='-') f=2; else if(a[e]=='*') f=3; else if(a[e]=='/') f=4; else if(a[e]=='%') f=5; } } if(f==1) cout<<b+d<<endl; else if(f==2) cout<<b-d<<endl; else if(f==3) cout<<b*d<<endl; else if(f==4) cout<<b/d<<endl; else if(f==5) cout<<b%d<<endl; } }
AC (2ms, 360KB) |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
char c;
long long int n,m;
cin>>t;
bool f;
for(int g=0;g<t;g++)
{
cin>>s;
string a,b;
f=true;
for(int i=0;i<s.length();i++)
{
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='%') c=s[i],f=false;
else if(s[i]>='0'&&s[i]<='9')
{
if(f)a+=s[i];
else b+=s[i];
}
}
stringstream ss(a);ss>>n;
stringstream s2(b);s2>>m;
if(c=='+') cout<<n+m<<endl;
else if(c=='-') cout<<n-m<<endl;
else if(c=='*') cout<<n*m<<endl;
else if(c=='/') cout<<n/m<<endl;
else cout<<n%m<<endl;
}
}
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv){ cin.tie(0); ios::sync_with_stdio(false); string a; int b,c,d,f; cin>>c; getline(cin,a); while(c--){ b=0; d=0; getline(cin,a); for(int e=0;e<a.size()+1;e++){ if(a[e]>='0'&&a[e]<='9') d=d*10+int(a[e])-48; else if(a[e]=='+'||a[e]=='-'||a[e]=='*'||a[e]=='/'||a[e]=='%'){ b=b+d; d=0; if(a[e]=='+') f=1; else if(a[e]=='-') f=2; else if(a[e]=='*') f=3; else if(a[e]=='/') f=4; else if(a[e]=='%') f=5; } } if(f==1) cout<<b+d<<endl; else if(f==2) cout<<b-d<<endl; else if(f==3) cout<<b*d<<endl; else if(f==4) cout<<b/d<<endl; else if(f==5) cout<<b%d<<endl; } }
AC (2ms, 360KB) |
#include <bits/stdc++.h> using namespace std; int main() { long long int a; while (cin >> a) { string b; long int one=0, two=0; int c=0, d, ans; for (int i=0;i<a;i++) { cin >> b; for (int m=0;m<b.size();m++) { if (b[m]>57) ; else if (b[m]=='+') { d='+'; c=m; break; } else if (b[m]=='-') { d='-'; c=m; break; } else if (b[m]=='*') { d='*'; c=m; break; } else if (b[m]=='/') { d='/'; c=m; break; } else if (b[m]=='%') { d='%'; c=m; break; } else { one+=b[m]-48; one*=10; } } one/=10; for (int m=c+1;m<b.size();m++) { if (b[m]>57) ; else { two+=b[m]-48; two*=10; } } two/=10; if (d==43) ans=one+two; else if (d==45) ans=one-two; else if (d==42) ans=one*two; else if (d==47) ans=one/two; else ans=one%two; cout << ans << endl; one=0; two=0; } } }
AC (2ms, 344KB)