QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613242#8251. Missing NumbereggtoastRE 0ms0kbC++172.1kb2024-10-05 13:48:142024-10-05 13:49:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 13:49:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 13:48:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
int main(){
    #ifndef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        int n = s.size() / 2;

        //cout << s << '\n';
        int flg = 0;
        int start = 0;
        while(n >= 1){
            string sub = (s.substr(0, n));
            string other = (s.substr(n, n));

            int x1 = stoi(sub);
            int x2 = stoi(other);

            //cout << "x1 " << x1 << ' ' << "x2 " << x2 << '\n';

            if((x2 == x1 + 1) || (x2 == x1 + 2)){
                if(x2 == x1 + 1){
                    flg = 1; //we know the starting point, so we look for the missing number
                    start = x1;
                } else {
                    flg =2; //case where 2nd number is missing
                    start = x1;
                }
               break;
            } 
            n--;
        }

        //if flg == 0, no missing numbers
        if(flg == 0){
            cout << 0 << '\n';
            continue;
        } else if (flg == 1){
            //we loop from start to end to find the missing number
            //pop off numbers until we find the missing number.
            int curr = start;
            while(!s.empty()){
                int digitsLeft = log10(curr) + 1;

                //cout << s << '\n';

                if(stoi(s.substr(0, digitsLeft)) != curr){
                    //cout << curr << " and " << s.substr(0, digitsLeft) << '\n';
                    cout << 1 << '\n';
                    cout << curr << '\n';
                    break;
                }

                s.erase(0, digitsLeft);
                curr++;
            }

            //if string is empty that means no missing numbers either
            if(s.empty())
                cout << 0 << '\n';

        } else if (flg == 2){
            cout << start + 1 << '\n';
            continue;
        }

        //cout << "flag is " << flg << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

1
891112

output:


result: