PAT-2019年冬季考试-甲级-7-1 Good in C (20分)——字符串

本题在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个大写英文字母A-Z,每个字母在C’s和.'s的7×5矩阵中。然后一个句子在一行中给出,以一个回车结束。句子由几个单词组成(每个单词不超过10个连续的大写英文字母),单词之间用大写英文字母以外的任何字符隔开。

保证至少有一个单词被给出。

代码:

//代码仅通过测试样例
//神圣之光原创代码
#include<bits/stdc++.h>
using namespace std;
vector <string> vi[26];
string s;
int main(){
	for(int i=0;i<26;i++){
		for(int j=0;j<7;j++){
			getline(cin,s);
			vi[i].push_back(s);
		}
	}
	getline(cin,s);
    int pre=0;
	for(int i=0;i<s.size();i++){
		if(s[i]>'Z' ||  s[i]<'A'){
			for(int p=0;p<7;p++){
				for(int j=pre;j<i-1;j++){
				  cout<<vi[s[j]-'A'][p]<<" ";
		    	}
		    	cout<<vi[s[i-1]-'A'][p]<<endl;;
			}
			pre=i+1;
			cout<<endl;	
		}
	}
	return 0;
}
//代码来源网络
#include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<string> v[26], word;
	string s, temp;
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < 7; j++){
			getline(cin, s);
			v[i].push_back(s);
		}		
	}
	getline(cin, s);
	for(int i = 0; i < s.length(); i++){
		if(s[i] <= 'Z' && s[i] >= 'A'){
			temp += s[i];
		}else{
			if(temp != ""){
				word.push_back(temp);
				temp = "";
			}
		}
	}
	if(temp != "") word.push_back(temp);
	for(int i = 0; i < word.size(); i++){
		for(int j = 0; j < 7; j++){
			for(int k = 0; k < word[i].size(); k++){
				int ind = word[i][k] - 'A';
				printf("%s%s", k == 0?"":" ", v[ind][j].c_str());
			}
			if( !(i == word.size() - 1 && j == 6) )printf("\n");
		}
		if(i != word.size() - 1) printf("\n");
	}
	return 0;
}
//代码来源网络
#include<iostream>
#include<cctype>
#include<vector>
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;
}

//本代码没有经过PAT官网测试,仅提供思路。
#include<bits/stdc++.h>
using namespace std;
string s[27][8];
int main(){
	for(int i=1;i<=26;i++){
		for(int j=1;j<=7;j++){
			cin>>s[i][j];
		}
	}
    string a;
    getchar ();
    getline(cin,a);
    int sit=0,qsit=0;//sit为当前位置,qsit为前一次位置。
    while(a.length() >= sit+1)
    {
    	if(a[sit]<='A' || a[sit]>='Z'){
    		for(int i=1;i<=7;i++){
		        for(int j=qsit;j<sit;j++){	
	            cout<<s[a[j]-'A'+1][i];
	            if(j<sit-1)printf(" ");
		        }
		        cout<<endl;
	       } 
	       qsit=sit+1;
	       if(a.length() > sit+1)cout<<endl;
		} 
        sit++;
	}
	//最后一个字符为字母,不是任意字符,将最后一个单词输出
	if(qsit < a.length()  ){
		for(int i=1;i<=7;i++){
		      for(int j=qsit;j<a.length();j++){	
	          cout<<s[a[j]-'A'+1][i];
	          if(j<a.length()-1)printf(" ");
		      }
		      cout<<endl;
	    } 
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

隔壁de小刘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值