4276擅长C PAT 1164
作者:
NikoNairre
,
2023-11-26 19:46:15
,
所有人可见
,
阅读 86
#include <iostream>
#include <stdio.h>
#include <vector>
#include <sstream>
using namespace std;
char g[30][10][10]; //use this to store all letters in big format, each is char[10][10]
int h_size = 7, w_size = 5; //the size of the big format letter
vector<string> split_word(string &s) //split the final given string into meaningful words
{
vector<string> res;
for (int i = 0; i < s.size(); i++ ) {
if (s[i] < 'A' or s[i] > 'Z') s[i] = ' '; //make non-letter char to ' ', which is useful in string split
}
stringstream strm(s);
while (strm >> s) { //after processing, using stringstream to split string into words according to space(' ')
res.push_back(s);
}
return res;
}
int cnt; //this global variable controls endl between output different words
void print_word(string cur) //print a word int big format
{
if (cnt) {puts(""); puts("");} //two endls are needed between words since we want an entire empty line
cnt++ ;
for (int i = 0; i < h_size; i++ ) { //we have to scan the entire word for several turns, each turn scans a single line
for (int j = 0; j < cur.size(); j++ ) { //traverse each letter
int id = cur[j] - 'A'; //get letter id in g
if (j) printf(" "); //' ' is required in different letters
printf("%s", g[id][i]);
}
if (i != h_size - 1) puts(""); //endl should be taken after the output of a single line except the final line
}
}
int main()
{
int i = 0;
while (i < 26) { //read all letters
for (int j = 0; j < h_size; j++ ) {
scanf("%s", g[i][j]);
//getline(cin, std::string)
}
i++ ;
}
string sentense;
getchar(); //the fronting scanf() will read another '\n', use this to filter it
getline(cin, sentense); //using getline to obtain the final string
vector<string> words = split_word(sentense);
for (auto cstr: words) {
print_word(cstr);
}
return 0;
}