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.
#include<iostream> #include<string> usingnamespace std; string letter[26][7]; string str[20]; intmain(){ //得到26个字母 for (int i = 0; i < 26; ++i) { for (int j = 0; j < 7; ++j) { cin>>letter[i][j]; } } getchar(); string sentence; getline(cin,sentence); int idx = 0; //按非字母划分单词 for (int i = 0; i < sentence.length(); ++i) { if (sentence[i]>='A'&&sentence[i]<='Z') { str[idx]+=sentence[i]; }else{ idx++; } } for (int i = 0; i < idx; ++i) { for(int j = 0; j< 7; j++){
for (int k = 0; k < str[i].length(); ++k) { int index = str[i][k]-'A'; for (int m = 0; m < 5; ++m) { cout<<letter[index][j][m]; } if (k<str[i].length()-1) { cout<<" "; } } cout<<endl; } if (i<idx-1) { cout<<endl; } }