60分不知道哪里出现了问题,求助!!!!!!!!

P1957 口算练习题

Exile_Code @ 2023-05-19 14:39:11

#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <cmath>
#include <bitset>
int letter[30];
int main()
{

    char a; char d;
    int t;
    cin >> t; 
    string s="";int b, c;
    while (t--) {
        b = 0; s = "";
        cin >> d;
        if (isalpha(d)) { 
            cin >> b >> c;
            a = d;
        }
        else {
            while (d != ' ') {
                b += b * 10 + (int)(d - '0');   
                d= getchar();
        //字符转int
            }
            cin >> c;
        }
     //符号判断
        if (a == 'a') {
            s += to_string(b);
            s += "+";
            s += to_string(c);
            s += "=";
            s += to_string(b + c);
        }
        else if(a=='b')
        {
            s += to_string(b);
            s += "-";
            s +=to_string(c);
            s += "=";
            s += to_string(b - c);
        }
        else {
            s += to_string(b);
            s += "*";
            s += to_string(c);
            s += "=";
            s += to_string(b * c);
        }
        cout << s << endl << s.size() << endl;
    }

    return 0;
}

by Exile_Code @ 2023-05-19 14:51:19

好像是b += b * 10 + (int)(d - '0'); 这里出了问题,输入11 99 会变成12 99 ,为什么呢?


by V1mnkE @ 2023-05-19 15:13:04

@Exile_Code += 改成 =


by Exile_Code @ 2023-05-19 15:46:56

@dennshokouni 谢谢大佬,不过 这是什么原因?


by V1mnkE @ 2023-05-19 16:01:08

@Exile_Code 具体不好用语言描述/kk,把 abcde 改成 abcde0 再加 f 才是 abcdef, 你这是 abcdef+abcde


|