本文主要是介绍PAT(甲级)2019年冬季考试7-1 Good in C (20 分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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.
这个题就是先把每个大写字母存储起来,然后把要输出的语句中的word先找出存储起来,然后按格式输出就好,要注意的是输入的语句可能有空格间隔开的单词,输入要用getline(cin, s)按行输入。输入输出用例在本页面显示有点问题,建议去pta系统观察原题。
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.
#include<bits/stdc++.h>
using namespace std;
struct Node {char word[7][6];
} letters[26];
bool isLetter(char c) {if (c >= 'A' && c <= 'Z') return true;else return false;
}
int main() {string s;for (int i = 0; i < 26; i++) {for (int j = 0; j < 7; j++) {scanf("%s", letters[i].word[j]);}}getchar();getline(cin, s);vector<string> ans;int start, end1, len;s = " " + s + " ";len = s.size();for (int i = 0; i < len; i++) {if ((!isLetter(s[i])) && (i - 1 >= 0) && isLetter(s[i - 1])) {end1 = i;ans.push_back(s.substr(start + 1, end1 - start - 1));}if ((!isLetter(s[i])) && (i + 1 < len) && isLetter(s[i + 1])) {start = i;}}for (int i = 0; i < ans.size(); i++) {if (i != 0) printf("\n\n");for (int x = 0; x < 7; x++) {if (x != 0) printf("\n");for (int j = 0; j < ans[i].size(); j++) {int id = ans[i][j] - 'A';if (j != 0) printf(" ");for (int y = 0; y < 5; y++) {printf("%c", letters[id].word[x][y]);}}}}return 0;
}
这篇关于PAT(甲级)2019年冬季考试7-1 Good in C (20 分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!