답안 #112035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112035 2019-05-17T06:11:18 Z fredbr Lun (COCI19_lun) C++17
5 / 50
2 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

bool valid(string const& s) {
    auto f = [](int x) {
        if (x > 10) return x/10+x%10;
        return x;
    };

    int acc = 0;
    for (int i = 0; i < s.size()-1; i++) {
        int x = s[i]-'0';

        if (i&1) acc += f(2*x);
        else acc += x;
    }

    acc = acc*9%10;

    return acc == s.back()-'0';
}

int main() {
    int n;
    cin >> n;

    string s;
    cin >> s;

    int xpos = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] >= '0' and s[i] <= '9') continue;
        xpos = i;
    }

    for (int i = '1'; i <= '9'; i++) {
        s[xpos] = i;
        if (valid(s)) {
            cout << char(i) << "\n";
            return 0;
        }
    }

}

Compilation message

lun.cpp: In function 'bool valid(const string&)':
lun.cpp:12:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size()-1; i++) {
                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Incorrect 2 ms 256 KB Output isn't correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Correct 2 ms 256 KB Output is correct
7 Incorrect 2 ms 256 KB Output isn't correct
8 Incorrect 2 ms 384 KB Output isn't correct
9 Incorrect 2 ms 384 KB Output isn't correct
10 Incorrect 2 ms 256 KB Output isn't correct