PAT-2019年冬季考试 - Grade 7-1 Good in C (20 minutes)

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 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.

 

Meaning of the questions:

You letter pattern 26 * 7 5, and then given a string of uppercase letters in a sentence, in which the capital letters printed, each word line, a space between letters, no extra row forward end of the word blank lines and spaces.

answer:

Seeing Zhayi feel very troublesome to skip. After doing a long, long time, he submitted numerous times. . .

I first want to print the pattern Blank lines are ignored, ans this first unified on the two-dimensional array, and finally print the two-dimensional array.

When a pattern is written ans then in the following figure, note the change and rr cc, not print a letter, rr + = 6, while printing a blank line. Encountered a non-capital letter symbol ( Note: more non-capital letters to make a sign to look ), then rr = 1, cc + = 7 , while the beginning I only took 13 points, the middle of three test points on too no, the reason may be the input string may contain spaces, but also because there is no record how many columns may print up to each big firms (col), each of the big firms are not the same, to be recorded, and then pay attention to small details. This last question I had was, was happy to wow a cry ~ finally finished, 100 friends, but also scared to next to the students. . . hhh

AC Code:

 

#include<bits/stdc++.h>
using namespace std;
char zm[30][15][15];
string s;
char ans[10000][10000];
int rnum[505]; 
int main(){
    for(int i=1;i<=26;i++){//存入zm中 
        for(int j=1;j<=7;j++){
            for(int k=1;k<=5;k++){
                cin>>zm[i][j][k];
            } 
        }
    } 
    getchar();
    getline(cin,s);//输入的字符串可能会包含空格
    int l=s.length();
    int col=1,cc=1;
    int rr=1;
    int f=0;//连续几个非大写字母的符号看作一个符号 
    for(int i=0;i<l;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            int lett=s[i]-'A'+1;
            f=1;
            for(int j=1;j<=7;j++){//打印一个字母到ans 
                for(int k=1;k<=5;k++){
                    ans[cc+j-1][rr+k-1]=zm[lett][j][k];
                    rnum[col]=max(rnum[col],rr+k-1);//用于记录每一大行最长有多长 
                }
            }
            rr+=6;//每打印一个字母在字母后面打印一个空行 
            for(int j=1;j<=7;j++){
                ans[cc+j-1][rr-1]=' ';
            }
        }else{
            if(f==1) {//如果符号之后又出出现过大写字母了 
                cc+=7;//行数+7 
                col++;//大行数+1 
                rr=1;    
            }
            f=0;
        }
    }
    if(f==0) col--;//最后一个符号不需要再多一行 
    for(int i=1;i<=col*7;i++){
        for(int j=1;j<=rnum[(i-1)/7+1];j++){
            cout<<ans[i][j];
        }
        if(i!=col*7) cout<<endl;// end of the line without spaces 
        IF (I% 7 == 0 && * I = COL! 7 ) COUT << endl; // not a blank line printing lines 7 
    }    
     return  0 ; 
}

 

 

 

Guess you like

Origin www.cnblogs.com/caiyishuai/p/12005345.html