返回列表 發帖

606 檢驗學號

1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。

2. 設計說明:
請撰寫一程式,讓使用者輸入三組學號,學號總共有6個字元,由左至右分別以s0~s5表示,s0~s4均是數字;s5是大寫英文字母的檢查碼。
s5的判斷規則:若公式「((s0+s2+s4)+(s1+s3)*5)%26」的計算結果為1,則s5為A;若計算結果為2,則s5為B,以此類推。請依序判斷使用者輸入的學號是否正確,正確則輸出「Pass」,否則輸出「Fail」。
提示:數字「0」的ASCII碼=48,英文字母「A」的ASCII碼=65。
提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。

3. 輸入輸出:
輸入說明
三組學號

輸出說明
三組學號是否合法

範例輸入
12345M
55237B
03805A

範例輸出
Pass
Pass
Fail


本帖隱藏的內容需要回復才可以瀏覽

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int as;
  5. int main()
  6. {
  7.     for(int i=0;i<3;i++)
  8.     {
  9.         getline(cin,str);
  10.         as=(((str[0]-'0')+(str[2]-'0')+(str[4]-'0'))+((str[1]-'0')+(str[3]-'0'))*5)%26;
  11.     if(str[5]-64==as)//((s0+s2+s4)+(s1+s3)*5)%26
  12.         cout<<"Pass"<<endl;
  13.     else
  14.         cout<<"Fail"<<endl;

  15.     }



  16.     return 0;
  17. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int str[3];
  4. int main()
  5. {
  6.     for(int i=0;i<3;i++)
  7.     {
  8.         getline(cin,str[i]);
  9.         
  10.     }
  11.    
  12.     return 0;
  13. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     for(int i=0;i<3;i++)
  6.     string s1;
  7.     getline(cin,s1);
  8.       
  9.     return 0;
  10. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.         for(int a=0;a<3;a++)
  7.         {
  8.                 int f=0,s=0;
  9.                 getline(cin,str);
  10.                 char r=str[5];
  11.                 for(int i=0;i<5;i+=2)
  12.                 {
  13.                         char c=str[i];
  14.                         f+=(c-=48);
  15.                 }
  16.                 for(int i=1;i<3;i++)
  17.                 {
  18.                         char c=str[i*2-1];
  19.                         s+=(c-=48);
  20.                 }
  21.                 int n=(f+s*5);
  22.                 int dataint=n%26;
  23.                 int datachar=r-=(65-1);
  24.                 if(dataint!=datachar)
  25.                         cout<<"Fail\n";
  26.                 else
  27.                         cout<<"Pass\n";
  28.         }
  29.         return 0;       
  30. }
複製代碼
打完了好爽

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     for(int i=0;i<3;i++)
  6.     {
  7.         string str;
  8.         int n[5];
  9.         getline(cin,str);
  10.         for(int j=0;j<5;j++)
  11.             n[j]=str[j];
  12.         int res=((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  13.         if(res==str[5]-'A'+1)
  14.             cout<<"Pass"<<endl;
  15.         else
  16.             cout<<"Fail"<<endl;
  17.     }
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     for(int i=0;i<3;i++)
  6.     {
  7.         string str;
  8.         int n[5];
  9.         getline(cin,str);
  10.         for(int j=0;j<5;j++)
  11.             n[j]=str[j];
  12.         int res=((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  13.         if(res==str[5]-'A'+1)
  14.             cout<<"Pass"<<endl;
  15.         else
  16.             cout<<"Fail"<<endl;
  17.     }
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     for(int t=0; t<3; t++)
  6.     {
  7.         int n[5];
  8.         string str;
  9.         getline(cin,str);
  10.         for(int i=0; i<5; i++)
  11.             n[i] = str[i];
  12.         int res = ((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  13.         if(res==str[5]-'A'+1)
  14.             cout<<"Pass"<<endl;
  15.         else
  16.             cout<<"Fail"<<endl;
  17.     }
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. int main(){
  4.     for(int t=0;t<3;t++){
  5.         string str;
  6.         int n[5];
  7.         getline(cin,str);
  8.         for(int i=0;i<5;i++)
  9.             n[i]=str[i];
  10.         int res=((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  11.         if(res==str[5]-'A'+1)
  12.             cout<<"Pass"<<endl;
  13.         else
  14.             cout<<"Fail"<<endl;
  15.     }
  16.     return 0;
  17. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     for(int i=0;i<3;i++)
  6.     {
  7.         string str;
  8.         int n[5];
  9.         getline(cin,str);
  10.         for(int j=0;j<5;j++)
  11.             n[j]=str[j];
  12.         int res=((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  13.         if(res==str[5]-'A'+1)
  14.             cout<<"Pass"<<endl;
  15.         else
  16.             cout<<"Fail"<<endl;
  17.     }
  18.     return 0;
  19. }
複製代碼

TOP

返回列表