___HatsuneMiku___ @ 2023-10-06 19:45:56
大佬求助!!
#include <bits/stdc++.h>
using namespace std;
int change(string s){
int d;
stringstream sin;
sin<<s;
sin>>d;
return d;
}
string find(string s){
string t="";
for(int i=0;i<s.size();i++){
if(isdigit(s[i])){
t+=s[i];
}else if(t!=""){
return t;
}
}
return "";
}
int findl(string s){
for(int i=0;i<=s.size();i++){
if(isdigit(s[i]))
return i;
}
return -1;
}
int findr(string s){
for(int i=findl(s);i<=s.size();i++){
if(!isdigit(s[i+1]))
return i;
}
return -1;
}
int main() {
string s;
int n;
cin>>n;
char ch;
getchar();
for(int i=1;i<=n;i++){
getline(cin,s);
char t[1000];
if(s[0]>='a'&&s[0]<='c')ch=s[0];
int l,r;
l=change(find(s));
s.erase(0,findr(s)+2);
r=change(s);
switch(ch){
case 'a':
sprintf(t,"%d+%d=%d",l,r,l+r);
break;
case 'b':
sprintf(t,"%d-%d=%d",l,r,l-r);
break;
case 'c':
sprintf(t,"%d*%d=%d",l,r,l*r);
break;
}
cout<<t<<endl<<strlen(t)<<endl;
}
return 0;
}
by yzl0225 @ 2023-10-13 19:23:45
getline(cin,s);
不行
by yzl0225 @ 2023-10-13 19:26:39
可以去看一下这个