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; }