当前位置: 首页 > news >正文

PAT 1164 Good in C 测试点3,4

个人学习记录,代码难免不尽人意。

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.

#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中!
还有一个需要注意的地方(虽然我没出错),那就是两个单词之间可能有多个非字母字符,是其他测试点的测试。

http://www.lryc.cn/news/153894.html

相关文章:

  • LabVIEW对EAST长脉冲等离子体运行的陀螺稳态运行控制
  • Fragment
  • 哈希表-救赎金
  • vue3+vite+ts项目适配各种分辨率解决方案
  • Python Opencv实践 - 矩形轮廓绘制(直边矩形,最小外接矩形)
  • 大数据HBASE的详细使用
  • Sentinel 流量控制框架
  • leetcode原题: 跳水板
  • 深度学习入门(Python)学习笔记1
  • 苏州想要获得融资融券低利率账户的方法?怎么开融资融券账户?
  • 【LeetCode周赛】LeetCode第359场周赛
  • vue3+ts+tinynce在富文本编辑器菜单栏实现下拉框选择
  • 前端UI组件库深度解析:构建现代化的用户体验
  • leetcode 1326. Minimum Number of Taps to Open to Water a Garden
  • C++日期类的基本实现
  • 第六章:数据结构与算法-part3:数据结构算法提升
  • keras深度学习框架通过卷积神经网络cnn实现手写数字识别
  • Springboot启动异常 Command line is too long
  • PXE 装机(五十)
  • C++ 虚函数与纯虚函数
  • 警告:Provides transitive vulnerable dependency maven:org.yaml:snakeyaml:1.30
  • 中文命名实体识别
  • WPF CommunityToolkit.Mvvm Messenger通讯
  • 【杂言】写在研究生开学季
  • 渗透测试漏洞原理之---【任意文件读取漏洞】
  • 合宙Air724UG LuatOS-Air LVGL API控件-图片 (Image)
  • 仿京东 项目笔记2(注册登录)
  • Spark与Flink的区别
  • 未来智造:珠三角引领人工智能产业集群
  • 【Unity db】sqlite