个人学习记录,代码难免不尽人意。
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.
Sample Input:
…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!
Sample Output:
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.文章来源:https://www.toymoban.com/news/detail-706749.html
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stack>
#include<string>
#include<vector>
using namespace std;
const int maxn=1010;
int main(){
string letter[26][7];
for(int i=0;i<26;i++){
for(int j=0;j<7;j++){
string str;
getline(cin,str);
letter[i][j]=str;
}
}
string str;
getline(cin,str);
vector<string> temp;
string s="";
for(int i=0;i<str.size();i++){
if(str[i]>='A'&&str[i]<='Z'){
s=s+str[i];
}
else{
if(s!=""){
temp.push_back(s);
s="";
}
}
}
if(s!="") temp.push_back(s);
int count=temp.size();
for(int i=0;i<count;i++){
for(int k=0;k<7;k++){
for(int j=0;j<temp[i].size();j++){
cout << letter[temp[i][j]-'A'][k];
if(j!=temp[i].size()-1) cout << " ";
else cout <<endl;
}
}
if(i!=count-1) cout << endl;
}
}
这道题不要被冗长的输入吓到了,其实就是存储26个大写字母的输入然后按照要求输出即可。
这道题比较容易出错的就是空格和空行,不要少输入或者多输入,如果思路不清晰的话可以先做别的题,然后再回来看思路可能会解放。
我的问题主要出现在3,4测试点上一直过不去。后来我看了别人的解析才知道测试3,4是测试给的句子最后是字母的情况,如果按照我的判断方法的话,最后一个是字母没法加到vector容器中,所以需要在循环外面判断一下,如果字符串不为空的话,就把他加入到vector中!
还有一个需要注意的地方(虽然我没出错),那就是两个单词之间可能有多个非字母字符,是其他测试点的测试。文章来源地址https://www.toymoban.com/news/detail-706749.html
到了这里,关于PAT 1164 Good in C 测试点3,4的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!