徐大大 @ 2021-02-16 00:28:42
#include<string>
#include<cstdlib>
using namespace std;
int main()
{
int A[52];
int B[52][6];
int a,b,c,d,e,f,i;//b是上一个符号
string s1,s6,s7;//2~5是加减乘除 6储存符号
cin>>i;
for(a=1;a<=i;a++)
{
cin>>s1;
if(s1[0]=='a')
{
cin>>B[a][1]>>B[a][2];
A[a]=B[a][1]+B[a][2];
b=1;
s6[a]='+'; continue;
}
if(s1[0]=='b')
{
cin>>B[a][1]>>B[a][2];
A[a]=B[a][1]-B[a][2];
b=2;
s6[a]='-'; continue;
}
if(s1[0]=='c')
{
cin>>B[a][1]>>B[a][2];
A[a]=B[a][1]*B[a][2];
b=3;
s6[a]='*'; continue;
}
if(s1[0]!='a'&&s1[0]!='b'&&s1[0]!='c')
{
B[a][1]=atoi(s1.c_str());
if(b==1)
{
cin>>B[a][2];
A[a]=B[a][1]+B[a][2];
b=1;
s6[a]='+'; continue;
}
if(b==2)
{
cin>>B[a][2];
A[a]=B[a][1]-B[a][2];
b=2;
s6[a]='-'; continue;
}
if(b==3)
{
cin>>B[a][2];
A[a]=B[a][1]*B[a][2];
b=3;
s6[a]='*'; continue;
}}
}
for(a=1;a<=i;a++)
{
s7=to_string(B[a][1])+s6[a]+to_string(B[a][2])+'='+to_string(A[a]);
b=s7.size();
cout<<s7<<endl<<b<<endl;
}
}```
by szTom @ 2021-02-16 00:32:11
请把数组移至全局变量
by szTom @ 2021-02-16 00:33:23
using namespace std;
+ int A[52];
+ int B[52][6];
int main()
{
- int A[52];
- int B[52][6];
int a,b,c,d,e,f,i;//b是上一个符号
by SisconHL @ 2021-02-16 00:40:13
test
1926
+ 114514
- 1919810
0817
by SisconHL @ 2021-02-16 00:40:42
萌新求助那个颜色是怎么做到的哇
by szTom @ 2021-02-16 00:42:04
@hepta_lhd 语言选diff
by SisconHL @ 2021-02-16 00:42:55
+ 114514
- 1919810
ntql
by SisconHL @ 2021-02-16 00:43:16
@szTom 感谢大佬
by WanderingTrader @ 2021-02-16 07:31:00
这个语言吼啊 学到了
by 徐大大 @ 2021-02-16 11:24:11
@szTom 感谢大佬,还是在时间上挂了,估计to_string用的时间太多了