• 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 
    #include
    #include
    #include
    #include
    #include 
    #include
    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;
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51

    这道题不要被冗长的输入吓到了,其实就是存储26个大写字母的输入然后按照要求输出即可。
    这道题比较容易出错的就是空格和空行,不要少输入或者多输入,如果思路不清晰的话可以先做别的题,然后再回来看思路可能会解放。
    我的问题主要出现在3,4测试点上一直过不去。后来我看了别人的解析才知道测试3,4是测试给的句子最后是字母的情况,如果按照我的判断方法的话,最后一个是字母没法加到vector容器中,所以需要在循环外面判断一下,如果字符串不为空的话,就把他加入到vector中!
    还有一个需要注意的地方(虽然我没出错),那就是两个单词之间可能有多个非字母字符,是其他测试点的测试。

  • 相关阅读:
    CleanMyMac X的免费版电脑系统瘦身工具
    软考高项--第一章项目整体管理
    技术分享| 快对讲视频调度功能说明
    PDF文件在线预览
    FPBJXDN224、FPBJXDV224插头式电比例节流阀放大器
    HEC-RAS 1D/2D水动力与水环境模拟技术案例实践及拓展应用
    软件测试/测试开发/人工智能丨视觉与图像识别自动化测试
    # 杂谈偶感 × 基于QFD方法的质量屋构建
    java计算机毕业设计口腔医院患者服务系统源码+系统+mysql数据库+lw文档+部署
    JAVA智慧防疫上报系统服务端计算机毕业设计Mybatis+系统+数据库+调试部署
  • 原文地址:https://blog.csdn.net/horsetaill/article/details/132677949