7-1 Good in C (20分)

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

HWC.jpg

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.

Sample Input:

..C..
.C.C.
C...C
CCCCC
C...C
C...C
C...C
CCCC.
C...C
C...C
CCCC.
C...C
C...C
CCCC.
.CCC.
C...C
C....
C....
C....
C...C
.CCC.
CCCC.
C...C
C...C
C...C
C...C
C...C
CCCC.
CCCCC
C....
C....
CCCC.
C....
C....
CCCCC
CCCCC
C....
C....
CCCC.
C....
C....
C....
CCCC.
C...C
C....
C.CCC
C...C
C...C
CCCC.
C...C
C...C
C...C
CCCCC
C...C
C...C
C...C
CCCCC
..C..
..C..
..C..
..C..
..C..
CCCCC
CCCCC
....C
....C
....C
....C
C...C
.CCC.
C...C
C..C.
C.C..
CC...
C.C..
C..C.
C...C
C....
C....
C....
C....
C....
C....
CCCCC
C...C
C...C
CC.CC
C.C.C
C...C
C...C
C...C
C...C
C...C
CC..C
C.C.C
C..CC
C...C
C...C
.CCC.
C...C
C...C
C...C
C...C
C...C
.CCC.
CCCC.
C...C
C...C
CCCC.
C....
C....
C....
.CCC.
C...C
C...C
C...C
C.C.C
C..CC
.CCC.
CCCC.
C...C
CCCC.
CC...
C.C..
C..C.
C...C
.CCC.
C...C
C....
.CCC.
....C
C...C
.CCC.
CCCCC
..C..
..C..
..C..
..C..
..C..
..C..
C...C
C...C
C...C
C...C
C...C
C...C
.CCC.
C...C
C...C
C...C
C...C
C...C
.C.C.
..C..
C...C
C...C
C...C
C.C.C
CC.CC
C...C
C...C
C...C
C...C
.C.C.
..C..
.C.C.
C...C
C...C
C...C
C...C
.C.C.
..C..
..C..
..C..
..C..
CCCCC
....C
...C.
..C..
.C...
C....
CCCCC
HELLO~WORLD!

Sample Output:

C...C CCCCC C.... C.... .CCC.
C...C C.... C.... C.... C...C
C...C C.... C.... C.... C...C
CCCCC CCCC. C.... C.... C...C
C...C C.... C.... C.... C...C
C...C C.... C.... C.... C...C
C...C CCCCC CCCCC CCCCC .CCC.

C...C .CCC. CCCC. C.... CCCC.
C...C C...C C...C C.... C...C
C...C C...C CCCC. C.... C...C
C.C.C C...C CC... C.... C...C
CC.CC C...C C.C.. C.... C...C
C...C C...C C..C. C.... C...C
C...C .CCC. C...C CCCCC CCCC.

题目描述:

输入:前面26*7行给出A-Z的字母输出格式,每7行为一个字母;最后一行是需要按格式输出的字符串。单词由不是A~Z的字符分隔。

输出:每个单词占7行,单词的字母中间用一个空格隔开。输出严格按照规定,最后一行不需输出空行。


解题思路:先将每个字母的输出格式存入字符数组,以便查找。在使用getline()接收需要分割的字符串----这点严重警告,否则测试点1、2、3会显示错误,如果不用getline接收,当遇到空格字符串就不能完整接收。需要算好在哪里空行!不能多不能少,太严格了。。


#include<bits/stdc++.h>
using namespace std;
string str[200];
string s;
int main()
{
	for(int i=0; i<182; i++) cin >> str[i];
	getchar();
	getline(cin,s);
	string t = "";
	bool flag = false;
	for(int i=0; i<s.length(); i++){
		if(s[i]>'Z'||s[i]<'A'){
			if(t.length()>0){
				if(flag==true) cout << endl;
				for(int o2=0; o2<7; o2++){
					for(int o1=0; o1<t.length(); o1++){
						int k = t[o1]-'A';
						if(o1) cout << " ";
						cout << str[k*7+o2];
					}
					cout << endl;
				}
				t = "";
				flag = true;
			}
		}
		else{
			t += s[i];
		}
	}
	if(t.length()!=0){
		if(flag==true) cout << endl;
		for(int o2=0; o2<7; o2++){
			for(int o1=0; o1<t.length(); o1++){
				int k = t[o1]-'A';
				if(o1) cout << " ";
				cout << str[k*7+o2];
			}
			cout << endl;
		}
	}
	return 0;
}