#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int length(int a,int b,int c) {
int i = 0;
if (a < 0) { i++; }
while (a != 0) {
i++;
a /= 10;
}
if (b < 0) { i++; }
while (b != 0) {
i++;
b /= 10;
}
if (c < 0) { i++; }
while (c != 0) {
i++;
c /= 10;
}
return i + 2;
}
void output(char n,int a,int b) {
if (n == 'a') {
cout << a << '+' << b << '=' << a + b << endl;
cout << length(a, b, a + b) << endl;
}
if (n == 'b') {
cout << a << '-' << b << '=' << a - b << endl;
cout << length(a, b, a - b) << endl;
}
if (n == 'c') {
cout << a << '*' << b << '=' << a * b << endl;
cout << length(a, b, a * b) << endl;
}
}
int translate(char* ch,int len) {
int re = 0;
for (int i = 0; i < len; i++) {
re = re * 10 + (ch[i] - '0');
}
return re;
}
int main() {
char input[60][60],type='a';
int n,b,c,len1,len2;
int u, u1, u2;
cin >> n;
getchar(); //避免读取'\n'
for (int i = 0; i < n; i++) {
cin.getline(input[i], 60, '\n');
}
for (int i = 0; i < n; i++) {
if (input[i][0] > '9') {
type = input[i][0];
char ch1[10], ch2[10];
for (u=2,len1=0; input[i][u] != ' '; u++) {
ch1[len1] = input[i][u];
len1++;
}
b = translate(ch1, len1);
for (u += 1,len2=0; input[i][u] != '\0'; u++) {
ch2[len2] = input[i][u];
len2++;
}
c = translate(ch2, len2);
output(type, b, c);
}
else {
char ch1[10], ch2[10];
for (u = 0, len1 = 0; input[i][u] != ' '; u++) {
ch1[len1] = input[i][u];
len1++;
}
b = translate(ch1, len1);
for (u += 1, len2 = 0; input[i][u] != '\0'; u++) {
ch2[len2] = input[i][u];
len2++;
}
c = translate(ch2, len2);
output(type, b, c);
}
}
return 0;
}
请问各位大神,手测全对,洛谷ide过不了 输入: 4 a 64 46 275 125 c 11 99 b 46 64 输出: 64+46=110 9 275+125=400 11 11*99=1089 10 46-64=-18 9