PAT 1164 Good in C

1164 Good in C (20 分)

When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?

PAT 1164 Good in C

Input Specification:

Each input file contains one test case. For each case, the first part gives the 26 capital English letters A-Z, each in a 7×5 matrix of C's and .'s. Then a sentence is given in a line, ended by a return. The sentence is formed by several words (no more than 10 continuous capital English letters each), and the words are separated by any characters other than capital English letters.

It is guaranteed that there is at least one word given.

Output Specification:

For each word, print the matrix form of each of its letters in a line, and the letters must be separated by exactly one column of space. There must be no extra space at the beginning or the end of the word.

Between two adjacent words, there must be a single empty line to separate them. There must be no extra line at the beginning or the end of the output.

坑点

1.单词之间可能存在空格,所以要用getline不能用cin

2.单词之间,单词前,单词后存在多个字符。

3.输出不能有多余的空行,单词之间只能有一个空行。

#include<bits/stdc++.h>
using namespace std;
string s[30][10];
int main()
{
	for (int i = 0; i <= 25; ++i)
	{
		for (int j = 0; j <= 6; ++j)
		{
			cin >> s[i][j];
		}
	}
	string wor;
	getline(cin, wor);
	wor += " ";
	string word = "";
	int sz = wor.size();
	for (int i = 0; i < sz; ++i)
	{
		if (wor[i] <= 'Z' && wor[i] >= 'A')
		{
			word += wor[i];
		}
		else
		{
			if (i != 0 && (wor[i - 1] <= 'Z' && wor[i - 1] >= 'A'))
			{
				word += wor[i];
			}
		}
	}
	int pre = 0;
	sz = word.size();
	for (int i = 0; i < sz; ++i)
	{
		int x = word[i] - 'A';
		if (x <= 25 && x >= 0)
		{
			;
		}
		else
		{

			for (int j = 0; j <= 6; ++j)
			{
				for (int k = pre; k < i; ++k)
				{
					x = word[k] - 'A';
					cout << s[x][j];
					if (k != i - 1)cout << " ";
					else cout << endl;
				}
			}
			pre = i + 1;
			if (i != sz - 1)cout << endl;
		}
	}
}

 

上一篇:uniapp 微信发送订阅消息


下一篇:使用expect进行linux服务器批量首次登录