标签:题解 new int char org ace har AC bsp
这道题是考字符串处理,另外输入要使用c++的cin的神奇功能。
#include<bits/stdc++.h> using namespace std; int n;char ch;int a,b;char k; string INTtoSTRING(int x){ ostringstream oss; oss<<x; return oss.str(); } int main(){ scanf("%d",&n);getchar(); while(n--){ char q[300]; if(!(cin>>a)){ cin.clear(); cin>>ch>>a; } cin>>b; if(ch==‘a‘){ printf("%d+%d=%d\n",a,b,a+b); string str_a=INTtoSTRING(a); string str_b=INTtoSTRING(b); string str_c=INTtoSTRING(a+b); string str=str_a+‘+‘+str_b+‘=‘+str_c; printf("%d\n",str.length()); } if(ch==‘b‘){ printf("%d-%d=%d\n",a,b,a-b); string str_a=INTtoSTRING(a); string str_b=INTtoSTRING(b); string str_c=INTtoSTRING(a-b); string str=str_a+‘+‘+str_b+‘=‘+str_c; printf("%d\n",str.length()); } if(ch==‘c‘){ printf("%d*%d=%d\n",a,b,a*b); string str_a=INTtoSTRING(a); string str_b=INTtoSTRING(b); string str_c=INTtoSTRING(a*b); string str=str_a+‘+‘+str_b+‘=‘+str_c; printf("%d\n",str.length()); } } return 0; }
标签:题解 new int char org ace har AC bsp
原文地址:https://www.cnblogs.com/yzx1798106406/p/8992763.html