bj12z_wangziqian @ 2022-11-12 16:07:45
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
char a[10000];
long long b[10000];
long long c[10000];
int wieshu(int i)
{
int k=0,m=i;
if(i==0) return 1;
for(;i!=0;k++)
{
i/=10;
}
if(m<0) {return (k+1);}
else return k;
}
int main()
{
int n;
cin >> n;
for(int i = 0;i<n;i++)
{
cin >> a[i];
if(a[i]=='a'||a[i]=='b'||a[i]=='c')
{
cin >> b[i] >> c[i];
}
else
{
b[i] = a[i] - '0';
a[i] = a[i-1];
cin >> c[i];
}
}
for(int i = 0;i<n;i++)
{
if(a[i] == 'a')
{
cout << b[i] << "+" << c[i] << "=" << b[i]+c[i] << endl;
cout << wieshu(b[i]) + wieshu(c[i]) + wieshu(b[i]+c[i]) + 2 << endl;
}
if(a[i] == 'b')
{
cout << b[i] << "-" << c[i] << "=" << b[i]-c[i] << endl;
cout << wieshu(b[i]) + wieshu(c[i]) + wieshu(b[i]-c[i]) + 2 << endl;
}
if(a[i] == 'c')
{
cout << b[i] << "*" << c[i] << "=" << b[i]*c[i] << endl;
cout << wieshu(b[i]) + wieshu(c[i]) + wieshu(b[i]*c[i]) + 2 << endl;
}
}
return 0;
}
为啥过不了,只有六十分qwq
各路神仙帮帮本蒟蒻吧qwq
by JustinXiaoJunyang @ 2022-11-12 16:26:03
@bj12z_wangziqian
#include <iostream>
#include <string>
using namespace std;
int stoi(string l)
{
int p = 0;
for (int i = 0; i < l.length(); i++)
{
p = p * 10 + l[i] - '0';
}
return p;
}
int lenjs(int a, char b, int c, int d)
{
int cnt;
int t1 = a;
int t2 = c;
int t3 = d;
if (t3 < 0)
{
cnt = 3;
}
if (t3 >= 0)
{
cnt = 2;
}
if (t1 == 0)
{
cnt++;
}
if (t2 == 0)
{
cnt++;
}
if (t3 == 0)
{
cnt++;
}
while (t1 != 0)
{
cnt++;
t1 /= 10;
}
while (t2 != 0)
{
cnt++;
t2 /= 10;
}
while (t3 != 0)
{
cnt++;
t3 /= 10;
}
return cnt;
}
int x[1005];
char op[1005];
int y[1005];
int res[1005];
int len[1005];
//计算有x,op,y,分别代表第一个数、运算符号、第二个数。从cin输入得到。
//输入
/*用cin:
如果第一个字符串t的第一位是数字(既是代表第一个是数,是加法).
因此就要将该字符串存成变量x,并且op='+',再输入y。
如果第一个字符串是a||b||c,就op赋值,再输入x、y。
*/
int main()
{
int n;
cin >> n;
string t;
for (int i = 1; i <= n; i++)
{
cin >> t;
if ('a' <= t[0] && t[0] <= 'c')
{
if (t[0] == 'a')
{
op[i] = '+';
}
if (t[0] == 'b')
{
op[i] = '-';
}
if (t[0] == 'c')
{
op[i] = '*';
}
cin >> x[i] >> y[i];
}
if ('0' <= t[0] && t[0] <= '9')
{
x[i] = stoi(t);
cin >> y[i];
op[i] = op[i - 1];
}
}
for (int i = 1; i <= n; i++)
{
if (op[i] == '+')
{
res[i] = x[i] + y[i];
}
if (op[i] == '-')
{
res[i] = x[i] - y[i];
}
if (op[i] == '*')
{
res[i] = x[i] * y[i];
}
len[i] = lenjs(x[i], op[i], y[i], res[i]);
}
for (int i = 1; i <= n; i++)
{
cout << x[i] << op[i] << y[i] << "=" << res[i] << endl;
cout << len[i] << endl;
}
return 0;
}
by bj12z_wangziqian @ 2022-11-12 16:52:26
@JustinXiaoJunyang
感谢大佬
好人一生平安!
by JustinXiaoJunyang @ 2022-11-12 16:56:26
@bj12z_wangziqian 谢谢