csppass
连续 00 XP登录 / 注册
202017判断题数组与字符串普及-

程序(一):非空输入是否一定输出不同

题目

阅读下面的程序,回答问题。 #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; return 0; } 判断题:若输入的字符串不是空串,则输入的字符串与输出的字符串一定不一样。( )

考点拆解
程序阅读与结果判断
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词