用C++解决On an 8×8 grid of dots, a word consisting of lowercase Latin letters is written vertically in one column, from top to bottom. What is it? Input The input consists of multiple test cases. The first line of the input contains a single integer t (1≤t≤1000 ) — the number of test cases. Each test case consists of 8 lines, each containing 8 characters. Each character in the grid is either . (representing a dot) or a lowercase Latin letter (a –z ). The word lies entirely in a single column and is continuous from the beginning to the ending (without gaps). See the sample input for better understanding. Output For each test case, output a single line containing the word made up of lowercase Latin letters (a –z ) that is written vertically in one column from top to bottom. Example inputCopy 5 ........ ........ ........ ........ ...i.... ........ ........ ........ ........ .l...... .o...... .s...... .t...... ........ ........ ........ ........ ........ ........ ........ ......t. ......h. ......e. ........ ........ ........ ........ ........ .......g .......a .......m .......e a....... a....... a....... a....... a....... a....... a....... a....... outputCopy i lost the game aaaaaaaa
时间: 2023-12-19 07:05:20 浏览: 120
Sure! Here's a C++ code that solves the problem:
```cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
vector<string> grid(8);
for (int i = 0; i < 8; i++) {
cin >> grid[i];
}
string word;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (grid[j][i] != '.') {
word += grid[j][i];
}
}
}
cout << word << endl;
}
return 0;
}
```
This code reads the number of test cases and then for each test case, it reads the grid of characters. It then iterates over each column and adds the non-dot characters to the word variable. Finally, it prints the word for each test case.
I hope this helps! Let me know if you have any further questions.
阅读全文