Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
92566 牛延希 22计算算术表达式 C++ Wrong Answer 1 MS 272 KB 675 2024-10-05 17:13:14

Tests(0/2):


Code:

#include<iostream> using namespace std; int main(){ char s; int n,x,y,flag; string a; cin>>n; for(int i=0;i<n;i++){ cin>>a; x=y=0; flag=0; for(int j=0;j<a.size();j++){ if(a[j]>='0' && a[j]<='9'){ if(flag){ y=y*10+a[j]; }else{ x=x*10+a[j]; } }else{ flag=1; s=a[j]; } }if(s=='+'){ cout<<x+y<<endl; }else if(s=='-'){ cout<<x-y<<endl; }else if(s=='*'){ cout<<x*y<<endl; }else if(s=='/'){ cout<<x/y<<endl; }else{ cout<<x%y<<endl; } } return 0; }


Run Info:

------Input------
5 5+4 3*7 8/3 9-9 12%2
------Answer-----
9 21 2 0 0
------Your output-----
105 2805 1 0 40