When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?ios
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.算法
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.api
..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!
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*5的图案,而后给出一串包含大写字母和其余字符的句子,把里面的大写字母打印出来,每一个单词一行,单词内的字母间空一列,行前行末没有多余的空行和空格。数组
首先使用字符串数组s保存输入的全部A到Z的图像,那么对于任意大写字符@,int a=@-'A'
,其对应的图案为$7a$~$7a+6$。接着就是考虑如何输出其中的全部大写字母,因为每个单词都得进行换行输出,这里采用按照单词进行分块,每一次输出一个单词而后换行输出下一个单词,那么就得在输入的字符串中提取出所须要的单词,这里使用string temp暂存当前保存的单词,初始为空,而后只要遇到A到Z就添加到temp中,不然只要temp非空就添加到单词集合result中,并重置temp为空,最后在循环退出的时候,若是temp非空,就将temp添加到result中便可。代码以下:测试
vector<string> result; for(char i : r){ if(i>='A'&&i<='Z'){ temp += i; } else { // 两个单词之间有多是多个非英文字母分隔的。 if(temp!=""){ result.push_back(temp); temp = ""; } } } // 最后有多是英文字母结尾 if(temp!=""){ result.push_back(temp); }
而后就是输出了,这里采用的输出方式为一行一行的输出,具体作法就是对于每个单词,每一行遍历单词中的每个字符,而后输出每个字符图案的第一行,每输出7行就说明输出完一个单词进而换行输出下一个单重,知道result的单词所有输出完毕便可,代码以下:spa
for(int k=0;k<result.size();++k){ // 对于每个单词进行输出 string word = result[k]; for(int line=0;line<7;++line){ // 每次输出line行的全部单词的字符串 for(int i=0;i<word.size();++i){ int a = word[i]-'A'; //7*a+line就是须要每个单词须要输出的行 printf("%s",s[7*a+line].c_str()); if(i<word.size()-1) printf(" "); } // 一行输出完毕,得回车 printf("\n"); } if(k<result.size()-1){ // 不是最后一个单词 printf("\n"); } }
HE@LLO!@#$WORLD!
C...C CCCCC C...C C.... C...C C.... CCCCC CCCC. C...C C.... C...C C.... C...C CCCCC C.... C.... .CCC. C.... C.... C...C C.... C.... C...C C.... C.... C...C C.... C.... C...C C.... C.... C...C 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.
HELLO~
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.
#include<cstdio> #include<string> #include<iostream> #include<vector> using namespace std; string s[183]; int main(){ for(int i=0;i<182;++i){ getline(cin,s[i]); } string r; getline(cin,r); string temp; vector<string> result; for(char i : r){ if(i>='A'&&i<='Z'){ temp += i; } else { // 两个单词之间有多是多个非英文字母分隔的。 if(temp!=""){ result.push_back(temp); temp = ""; } } } // 最后有多是英文字母结尾 if(temp!=""){ result.push_back(temp); } for(int k=0;k<result.size();++k){ // 对于每个单词进行输出 string word = result[k]; for(int line=0;line<7;++line){ // 每次输出line行的全部单词的字符串 for(int i=0;i<word.size();++i){ int a = word[i]-'A'; //7*a+line就是须要每个单词须要输出的行 printf("%s",s[7*a+line].c_str()); if(i<word.size()-1) printf(" "); } // 一行输出完毕,得回车 printf("\n"); } if(k<result.size()-1){ // 不是最后一个单词 printf("\n"); } } return 0; }