답안 #166127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166127 2019-11-30T21:13:00 Z itiam Lun (COCI19_lun) C++11
50 / 50
2 ms 504 KB
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>

using namespace std;
int L[100];
int L2[10]={0,5,1,6,2,7,3,8,4,9};

int main(){
    int N,par=0,parn=0,y,z;
    char x;
    cin >> N;
    if (N%2==0)  parn=1;
    for (int i=0;i<N;i++){
        cin >> x;
        if (x!='x'){
            y=2*((int)x-48);
            if (y>=10)   y=(y%10)+1;
            z=(int)x-48;
        }
        else{
            y=-1;
            z=-1;
        }
        if (parn==1){
            if ((i+1)%2>0){
                L[i]=y;
                if (y==-1) par=1;
            }
            else L[i]=z;
        }
        else if (parn==0){
            if ((i+1)%2==0){
                L[i]=y;
                if (y==-1) par=1;
            }
            else L[i]=z;
        }
    }
    int zb=0,zad,br=0,xx;
    for (int i=0;i<N-1;i++){
        if (L[i]==-1)   continue;
        zb+=L[i];
    }
    if (L[N-1]!=-1){
        zad=L[N-1];
        for (int i=0;i<10;i++){
            br=((zb+i)*9)%10;
            if (br==zad){
                xx=i;
                break;
            }
        }
        if (par==1) xx=L2[xx];
    }
    else{
        xx=((zb)*9)%10;
    }
    cout << xx;
    return 0;
}

Compilation message

lun.cpp: In function 'int main()':
lun.cpp:56:23: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (par==1) xx=L2[xx];
                     ~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 128 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct