返回列表 發帖

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 n[5];
  5. int main()
  6. {

  7.     for(int i=0;i<3;i++)
  8.     {
  9.          cin>>str;
  10.         for(int j=0;j<5;j++)
  11.            n[j]=str[j]-'0';
  12.         int x=((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  13.         if(x==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. string str;
  4. int n[5];
  5. int main()
  6. {

  7.     for(int i=0;i<3;i++)
  8.     {
  9.          cin>>str;
  10.         for(int j=0;j<5;j++)
  11.            n[j]=str[j]-'0';
  12.         int x=((n[0]+n[2]+n[4])+(n[1]+n[3])*5)%26;
  13.         if(x==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.         string str;
  8.         int n[5];
  9.         getline(cin, str);
  10.         for(int i=0; i<5; i++)
  11.             n[i]=str[i]-'0';
  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.         string str;
  8.         int n[5];
  9.         getline(cin,str);
  10.         for(int i=0;i<5;i++)
  11.             n[i]=str[i]-'0';
  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. }
複製代碼

TOP

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     for(int j=0;j<3;j++){
  6.         string str;
  7.         int n[5];
  8.         cin>>str;
  9.         for(int i=0;i<str.size();i++){
  10.             n[i]=str[i]-'0';
  11.         }
  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

返回列表