二、阅读程序-1

阅读程序(程序输入不超过数组或字符串定义的范围)
注:2020 CSP-J真题

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cstdlib>
#include <iostream>
using namespace std;

char encoder[26]={'C','S','P',0};
char decoder[26];

string st;

int main() {
    int k=0;
    for (int i = 0;  i<26 ; i++) 
        if(encoder[i]!=0)++k;
    for (char x = 'A'; x <= 'Z'; ++x) {
        bool flag=true;
        for (int i = 0; i < 26; ++i)
            if(encoder[i]==x){
                flag= false;
                break;
            }
          if(flag){
              encoder[k]=x;
              ++k;
          }
    }
    for (int i = 0; i < 26; ++i)
        decoder[encoder[i]-'A']= i+'A';
    cin>>st;
    for (int i = 0; i < st.length(); ++i)
        st[i]=decoder[st[i]-'A'];
    cout<<st<<endl;
    return 0;
}
Scroll to Top