# 猜字母 把abcd...s共19个字母组成的序列重复拼接106次,得到长度为2014的串。 接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母。 得到的新串再进行删除奇数位置字母的动作。如此下去,最后只剩下一个字母,请写出该字母。 以下程序哪项运行后不能得到正确答案? ## aop ### before ```c #include using namespace std; ``` ### after ```c ``` ## 答案 ```c int a[2014]; int main() { int count = 2014; for (int i = 0; i < 2014; i++) { a[i] = i + 1; } do { for (int i = 0; i <= count - 1; i += 2) a[i] = 0; count = 0; for (int j = 0; j <= 2013; j++) { if (a[j] != 0) { a[count] = a[j]; a[j] = 0; count++; } } } while (count != 1); cout << char('a' + (a[0] % 19)); return 0; } ``` ## 选项 ### A ```c int main() { string s = "abcdefghijklmnopqrs"; string str; for (int i = 0; i < 106; i++) { str += s; } while (str.length() > 1) { for (int i = 0; i < str.length(); i++) { str.erase(i, 1); } } cout << str; return 0; } ``` ### B ```c int main() { char a[2015]; int t = 0; for (int j = 0; j < 106; j++) for (int i = 0; i < 19; i++) a[t++] = 'a' + i; a[t] = 0; int k; while (t != 1) { k = 0; for (int j = 1; j < t; j += 2) a[k++] = a[j]; a[k] = '\0'; t = k; } cout << a << endl; return 0; } ``` ### C ```c int main() { vector vc1; int i; for (i = 0; i < 2014; i++) vc1.push_back('a' + (i % 19)); while (vc1.size() != 1) { vector vc2; for (i = 1; i < vc1.size(); i += 2) vc2.push_back(vc1[i]); vc1.assign(vc2.begin(), vc2.end()); } cout << vc1[0] << endl; return 0; } ```