题解:P10372 [AHOI2024 初中组 / 科大国创杯初中组 2024] 家庭作业

· · 题解

解题思路

每次读入「数字 + 字符 + 数字 + 字符 + 数字」,忽略两个字符,判断前两个数字的和是否等于第三个数字即可。

参考代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--)
    {
        int a,b,c;
        char f;
        cin>>a>>f>>b>>f>>c;
        cout<<(a+b==c?"Right!":"Wrong!")<<'\n';
    }
    return 0;
}