solution.md 1.9 KB
Newer Older
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
# 猜字母
把abcd...s共19个字母组成的序列重复拼接106次,得到长度为2014的串。  
接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母。   
得到的新串再进行删除奇数位置字母的动作。如此下去,最后只剩下一个字母,请写出该字母。  

## aop
### before
```cpp
#include <iostream>
#include <vector>
using namespace std;
```
### after
```cpp

```

## 答案
```cpp
int main()
{
	vector<char> vc1;
	int i;
	for (i = 0; i < 2014; i++)
		vc1.push_back('a' + (i % 19));
	while (vc1.size() != 1)
	{
		vector<char> vc2;
		cout << vc1.size() << endl;
		for (i = 1; i < vc1.size(); i += 2)
			vc2.push_back(vc1[i]);
		vc1.assign(vc2.begin(), vc2.end());
		cout << vc1.size() << endl;
	}
	cout << vc1[0] << endl;
	return 0;
}
```
## 选项

### A
```cpp
int main()
{
	vector<char> vc1;
	int i;
	for (i = 0; i < 2014; i++)
		vc1.push_back('a' + (i % 19));
	while (vc1.size() != 1)
	{
		vector<char> vc2;
		cout << vc1.size() << endl;
		for (i = 0; i < vc1.size(); i++)
			vc2.push_back(vc1[i]);
		vc1.assign(vc2.begin(), vc2.end());
		cout << vc1.size() << endl;
	}
	cout << vc1[0] << endl;
	return 0;
}
```

### B
```cpp
int main()
{
	vector<char> vc1;
	int i;
	for (i = 0; i < 2014; i++)
		vc1.push_back('a' + (i % 19));
	while (vc1.size() != 1)
	{
		vector<char> vc2;
		cout << vc1.size() << endl;
		for (i = 0; i < vc1.size(); i += 1)
			vc2.push_back(vc1[i]);
		vc1.assign(vc2.begin(), vc2.end());
		cout << vc1.size() << endl;
	}
	cout << vc1[0] << endl;
	return 0;
}
```

### C
```cpp
int main()
{
	vector<char> vc1;
	int i;
	for (i = 0; i < 2014; i++)
		vc1.push_back('a' + (i % 19));
	while (vc1.size() != 1)
	{
		vector<char> vc2;
		cout << vc1.size() << endl;
		for (i = 0; i < vc1.size(); i += 2)
			vc2.push_back(vc1[i]);
		vc1.assign(vc2.begin(), vc2.end());
		cout << vc1.size() << endl;
	}
	cout << vc1[0] << endl;
	return 0;
}
```