本题在2021年12月之后才会解封放到免费题库里,目前需要收费。

题目:

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.

题意

给出26个大写字母的7×5矩阵,然后给出以回车结尾的字符串,输出大写字母组成的单词,如果中间有非大写字母的,当做是分割符,换行即可。但是最后一个单词后面不要换行了。

题眼

1.7×5矩阵
本来想到要用26×7×5的三维矩阵来存26个大写字母的图像,但是其实二维的字符串数组或者二维向量也行的
2.大写字母
头文件cctype中isupper()能判断是不是大写字母
3.字符串有非大写字母
这个非大写字母有可能是空格、回车等转义字符,最好用scanf("%c")来读

## 陷阱(这部分我再斟酌一下,晚一点更)
最烧脑子的部分是什么,你有想法吗?
就是打印的时候怎么表达出目前量对26×7×5的三维矩阵的转换。
我用的办法是:vector<int> word读进大写字母,然后写出转换的关系式:

w[i][j]=v[word[k]][i][j%6]
w放的是单词的图像,i为行,j为列
这里面还要注意的就是这个余6操作,能顺利地把每个字母都正确复制进去。
另一个陷阱就是换行代表了结束,和不允许最后有多余的空格或者换行。

新版代码

只经过本地测试的

#include<iostream>
#include<cctype>
#include<vector>
using namespace std;
string a[26][7],str;
vector<int> word;
int main(){for(int i=0;i<26;i++){for(int j=0;j<7;j++){cin>>a[i][j];}}cin.ignore();//因为cin会把换行符留在缓冲区,所以这里要将换行符忽略掉getline(cin,str);bool flag=false;for(int i=0;i<str.size();i++){if(isupper(str[i]) && i==str.size()-1)word.push_back(str[i]-'A');if(isupper(str[i]) && i!=str.size()-1){word.push_back(str[i]-'A');}else{if(flag)cout<<endl<<endl;for(int k=0;k<7;k++){for(int j=0;j<word.size();j++){if(j!=0)cout<<" ";cout<<a[word[j]][k];}if(k!=6)cout<<endl;}word.clear();flag=true;}}return 0;
}

旧版代码

#include<iostream>
#include<cctype>
#include<vector>
using namespace std;
int n,m;
char v[26][7][5];
int main(){for(int i=0;i<26;i++){for(int j=0;j<7;j++){scanf("%c%c%c%c%c\n",&v[i][j][0],&v[i][j][1],&v[i][j][2],&v[i][j][3],&v[i][j][4]);}}char ch;bool f=false;vector<int> word;while(~scanf("%c",&ch)){if(isupper(ch)){word.push_back(ch-'A');}else if(!word.empty()){if(f)printf("\n\n");int len=word.size()*6-1;char w[7][len];for(int i=0;i<7;i++){int k=0;for(int j=0;j<len;j++){if(j>0&& (j+1)%6==0){w[i][j]=' ';k++;}else w[i][j]=v[word[k]][i][j%6];}}for(int i=0;i<7;i++){if(i!=0)printf("\n");for(int j=0;j<len;j++){if(w[i][j]-' '!=0)printf("%c",w[i][j]);else printf(" ");}}//if(ch=='\n')return 0;//写不写都行,这里没测试点f=true;word.clear();}}return 0;
}

备考汇总贴:2020年3月PAT甲级满分必备刷题技巧

如果喜欢我的博客,请为我点个赞,也欢迎多评论、转发,感谢!!

PAT-2019年冬季考试-甲级-7-1 Good in C (20分)超详解,几招就满分通过相关推荐

  1. 【PAT】2021年冬季考试甲级,摸鱼游记、92分

    T1,简单模拟,20/20分 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+10; int a[max ...

  2. 2019年 第10届 蓝桥杯 Java B组 决赛真题详解及小结

    蓝桥杯 Java B组 省赛决赛 真题详解及小结汇总[2013年(第4届)~2020年(第11届)] 第11届 蓝桥杯-第1.2次模拟(软件类)真题-(2020年3月.4月)-官方讲解视频 说明:大部 ...

  3. pat甲级考试报名费_PAT(甲级)2019年冬季考试 题解

    总结写在前头: 考了字符串.链表(伪链表).图.树.考点比较均衡. 本次考试难度还行,需要较扎实的数据结构底子,对于字符串处理的技巧有一定的要求. 说句题外话,字符串是个重点,主要因为很多人会忽视字符 ...

  4. PAT(乙级)2019年冬季考试【答案+题解】

    7-1 2019数列 (15分) 7-2 老鼠爱大米 (20分) 7-3 String复读机 (20分) 7-4 擅长C (20分) 7-5 区块反转 (25分) 7-1 2019数列 (15分) 把 ...

  5. PAT(甲级)2019年冬季考试 7-2 Block Reversing

    这题是做过的,B1025,我还总结过,果然早晚复相逢,只改了一点点,见1025 反转链表. 点睛之笔是结构体数组的哈希,地址既做下标,又有实际含义,妙啊. node[add].add = add; 当 ...

  6. PAT(甲级)2019年冬季考试 7-4 Cartesian Tree

    这道题利用的是最小堆和中序排序的属性:只要知道根节点,就能得出哪些属于左子树,哪些属于右子树. 开始我一直报段错误,经过筛查,发现是创建树的函数忘记写返回语句 return root. AC代码 #i ...

  7. PAT(甲级)2019年冬季考试7-1 Good in C (20 分)

    7-1 Good in C (20 分) When your interviewer asks you to write "Hello World" using C, can yo ...

  8. PAT-2019年冬季考试-甲级 7-1 Good in C (20分)

    7-1 Good in C (20分) When your interviewer asks you to write "Hello World" using C, can you ...

  9. 【PAT甲级 排序】1096 Consecutive Factors (20 分) C++ 全部AC

    题目 难倒是不难,暴力破解即可.要注意的就是开longlong,以及开方时,不要丢失临界值,还有如果子序列长度为0的话,输出num本身(因为计算的时候不考虑1这个因数). 一开始想出来一种O(n)的算 ...

最新文章

  1. 让线上学习不打折扣,作业帮如何用技术促进课堂高频互动场?
  2. ansible部署tomcat及 include机制
  3. RocEDU.课程设计2018 第二周进展 博客补交
  4. docker php composer 使用_宿主机nginx与docker的PHP搭配使用
  5. 控制器属性传值的一些小问题
  6. svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
  7. linux关闭远程服务器,linux – 远程主机关闭SSH连接
  8. 计算机上的usb设备是什么东西,联接一个USB的线在电脑桌上方便插U盘的东西叫什么?...
  9. 使用poll实现的io多路复用服务端和客户端
  10. IPv4地址在mysql的存储
  11. flex布局演示(可线上运行项目)
  12. JNDI RMI 注入(Log4j2漏洞)
  13. abort()和exit()的区别
  14. 安卓手机里的“其他”为何占用如此多?我用adb+excel来处理
  15. ppt循环动画的制作
  16. 【Spark】Spark Quick Start(快速入门翻译)
  17. ういんどみる公开了它用的游戏引擎,CatSystem2
  18. 非华为电脑如何与matepad pro进行多屏协同,以及如何处理连接失败等问题
  19. 类的成员函数指针(比较深入)
  20. JNI 之Java和c/c++交互,提升Java变成效率

热门文章

  1. 神经网络压缩(6):Exploring the Regularity of Sparse Structure in Convolutional Neural Networks
  2. Java基础321 - 如何重写equals方法
  3. 快速调用编辑器来写一条长,复杂或难的命令--用Enki学Linux系列(5)
  4. uniapp分享到微信流程
  5. 开发在线文档时,这个技术难点你解决了吗?
  6. c++类与对象(一)
  7. 一键搭建Ubuntu开发环境
  8. 微型计算机字,小型微型计算机系统
  9. 【专栏集合】ConcurrentHashMap
  10. 关于MC34063的奇怪问题参考解决方案(mc34063升压失败、输出等于输入,输出电压低于输入)