写的第一个pat甲级题目纪念一下。感觉是一道比较麻烦的模拟题。调格式调了有1个多小时(题目写到这份上已经算失败了。本人太弱了)
下附20分代码:
#include<bits/stdc++.h>
using namespace std;
//存26个字母
char arr[100][7][5];
//用题目给的26个字母打印字符串
void printc(string s){
for(int i=0;i<7;i++){
for(int x=0;x<s.size();x++){
char c = s[x];
for(int j=0;j<5;j++){
cout << arr[int(c)][i][j];
}
if(x != s.size()-1) cout << " ";
}
cout << endl;
}
}
int main(){
//录入
for(int i=65;i<=90;i++)
for(int j=0;j<7;j++)
for(int k=0;k<5;k++)
cin >> arr[i][j][k];
cin.ignore();
string todo;
getline(cin,todo);
int i,j;
bool isF = true;
for(i=0;i<todo.size();){
if(int(todo[i]) < 65 || int(todo[i]) > 90 ){ i++;continue;}
for( j=i;j<todo.size();j++){
if(int(todo[j]) < 65 || int(todo[j]) > 90 ){ //不是字母了
if(!isF){
cout << endl;
}
isF = false;
printc(todo.substr(i,j-i));
break;
}else if(j == todo.size()-1 && int(todo[j]) >= 65 && int(todo[j]) <= 90 ){//以字母结尾
if(!isF){
cout << endl;
}
isF = false;
printc(todo.substr(i,j-i+1));
break;
}
}
i = j+1;
}
return 0;
}