답안 #570662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570662 2022-05-31T02:15:43 Z AGE Lun (COCI19_lun) C++14
50 / 50
1 ms 212 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int long long
using namespace std;

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

    string s;
    cin>>s;

    reverse(s.begin(),s.end());
    int index;

    for(int i=0;i<s.size();i++)
        if(s[i]=='x')
            index=i;

    int sum=0;

    if(index==0){

        for(int i=1;i<s.size();i++){
            if(i%2!=0){

                int x=s[i]-'0';
                x*=2;

                int y=0;
                while(x){
                    y+=x%10;
                    x/=10;
                }

                sum+=y;
            }

            else
                sum+=s[i]-'0';
        }


        sum*=9;
        cout<<sum%10<<endl;
    }

    else if(index%2==0){

        for(int i=1;i<s.size();i++){

            if(s[i]=='x')
                continue;

            if(i%2!=0){

                int x=s[i]-'0';
                x*=2;

                int y=0;
                while(x){
                    y+=x%10;
                    x/=10;
                }

                sum+=y;
            }

            else
                sum+=s[i]-'0';
        }

        sum*=9;
        for(int i=0;i<=1000;i++){
            if((sum+(i*9))%10==s[0]-'0'){
                cout<<i<<endl;
                break;
            }
        }

    }

    else if(index%2!=0){

        for(int i=1;i<s.size();i++){

            if(s[i]=='x')
                continue;

            if(i%2!=0){

                int x=s[i]-'0';
                x*=2;

                int y=0;
                while(x){
                    y+=x%10;
                    x/=10;
                }

                sum+=y;
            }

            else
                sum+=s[i]-'0';
        }

        sum*=9;
        for(int i=0;i<=1000;i++){
            int x=i;
            x*=2;

            int y=0;
            while(x){
                y+=x%10;
                x/=10;
            }
            if((sum+(y*9))%10==s[0]-'0'){
                cout<<i<<endl;
                break;
            }
        }

    }

    return 0;
}

Compilation message

lun.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~
lun.cpp: In function 'int main()':
lun.cpp:19:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
lun.cpp:27:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i=1;i<s.size();i++){
      |                     ~^~~~~~~~~
lun.cpp:53:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int i=1;i<s.size();i++){
      |                     ~^~~~~~~~~
lun.cpp:88:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int i=1;i<s.size();i++){
      |                     ~^~~~~~~~~
lun.cpp:25:5: warning: 'index' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |     if(index==0){
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct