其他分享
首页 > 其他分享> > PAT 2019年冬季 7-1 Good in C (20 分)

PAT 2019年冬季 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?

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.

实现思路:

水题,三位数组输出即可。

AC代码:

#include <iostream>
#include <cstring>
#include <cctype>
#include <vector>
using namespace std;
char printVal[26][7][6];

bool judge(char c) {
	if(c>='A'&&c<='Z') return true;
	else return false;
}

int main() {
	for(int i=0; i<26; i++) {
		for(int j=0; j<7; j++) {
			scanf("%s",printVal[i][j]);
		}
	}
	string str,ans="";
	getchar();
	getline(cin,str);
	vector<string> sq;
	for(int i=0; i<str.length(); i++) {
		if(judge(str[i])) {
			ans+=str[i];
		} else if(ans.size()>0) {
			sq.push_back(ans);
			ans="";
		}
	}
	if(ans.size()>0) sq.push_back(ans);
	for(int i=0; i<sq.size(); i++) {//控制总字母数
		str=sq[i];
		for(int j=0; j<7; j++) {//控制单词打印行数
			for(int u=0; u<str.length(); u++) {//控制一行分段
				int cPos=str[u]-'A';
				printf("%s",printVal[cPos][j]);
				if(u<str.length()-1) printf(" ");
				else printf("\n");
			}
		}
		if(i<sq.size()-1) printf("\n");
	}
	return 0;
}

标签:...,Good,PAT,..,....,CCCC,2019,CCCCC,CCC
来源: https://www.cnblogs.com/coderJ-one/p/14423404.html