Advertisement
gha890826

0312-1 ISBN編碼

Mar 12th, 2021 (edited)
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string in;
  8.     while(cin>>in)
  9.     {
  10.         string ori=in;
  11.         for(int i=0;i<in.length();i++)
  12.         {
  13.             if (in[i]=='-')
  14.             {
  15.                 in.erase(i,1);
  16.             }
  17.         }
  18.         int check=0;
  19.         for(int i=0;i<9;i++)
  20.         {
  21.             check+=(in[i]-'0')*(i+1);
  22.             //cout<<"***chcke="<<check<<endl;
  23.         }
  24.         check%=11;
  25.         if(check==10)
  26.         {
  27.             if(in[9]=='X')
  28.             {
  29.                 cout<<"OK"<<endl;
  30.             }
  31.             else
  32.             {
  33.                 ori[ori.length()-1]='X';
  34.                 cout<<ori<<endl;
  35.             }
  36.         }
  37.         else
  38.         {
  39.             if(check==(in[9]-'0'))
  40.             {
  41.                 cout<<"OK"<<endl;
  42.             }
  43.             else
  44.             {
  45.                 ori[ori.length()-1]=('0'+check);
  46.                 cout<<ori<<endl;
  47.             }
  48.         }
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement