阅读程序(程序输入不超过数组或字符串定义的范围)
注: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; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
2.若输入的字符串不是空串,则输入的字符串与输出的字符串一定不一样。
3. 若将第12行的”i<26″改为”i<16″,程序运行结果不会改变
4. 将第26行”i<26″改成”i<16″,程序结果不会改变。
5. 若输出字符串为”ABCABCABCA”,则下列说法正确的是( )?
6. 若输出的字符串为”CSPCSPCSPCSP”,则下列说法正确的是( )?