当你被面试官要求用 C 写一个“Hello World”时,有本事像下图显示的那样写一个出来吗?
..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!
solution
- 测试点0:单词与单词之间隔开一行
- 测试点1,2,3:最后一行给出的句子中有空格,要用getchar()先吸收换行再用getline()接收。注意前后都有可能出现非大写字母,注意滤过
#include<iostream>
#include<string>
using namespace std;
int main(){string s, all[26][7], t;int p = 0, e, flag = 0;for(int i = 0; i < 26; i++){for(int j = 0; j < 7; j++){cin >> all[i][j];}}getchar();getline(cin, t);while(p < t.size()){while(p < t.size() && (t[p] < 'A' || t[p] > 'Z')) p++;for(e = p; e < t.size() && t[e] >= 'A' && t[e] <= 'Z'; e++);if(flag) cout << endl;for(int i = 0; i < 7; i++){for(int j = p; j < e; j++){if(j != p) cout << " ";cout << all[t[j] - 'A'][i];}cout << endl;flag = 1;}for(p = e; p < t.size() && (t[p] < 'A' || t[p] > 'Z'); p++);}return 0;
}