样例过了,全WA求助QAQ
查看原帖
样例过了,全WA求助QAQ
1051196
C_Wang楼主2023/8/15 21:09
#include <bits/stdc++.h>

using namespace std;

int t;

int main()
{
    cin >> t;
    while(t--)
    {
        int a[12] = {0};
        int n, len = 0;
        cin >> n;
        if(n == 0)
        {
            cout << 1 << endl;
            continue;
        }
        while(n)
        {
            a[++len] = n % 10;
            n /= 10; 
        }
        int t = 0;
        for(int i = 1; i <= len; i++)
        {
            a[i] += t;
            t = 0;
            if(i == len && a[i] <= 0){
                len--;
                break;
            }
            if(a[i] == 9) continue;
            else if(a[i] >= 1 && a[i] <= 8)
            {
                a[i]++;
            }
            else if (a[i] <= 0){
                a[i]--;
                t += a[i];
                a[i] = 9;
            }
        }
        int res = 0;
        for(int i = 1; i <= len; i++)
        {
            res += a[i];
        }
        cout << res << endl;
    }
}

正常分类讨论写的QAQ

2023/8/15 21:09
加载中...