2019.12.7PAT冬季考试第一题 - 7-1 Good in C (20分)

PAT-2019年冬季考试-甲级-7-1 Good in C (20分)超详解,几招就满分通过 题目: 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... 阅读详情

第一题

7-1 Good in C (20分)

When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?

HWC.jpg

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.

作者: 陈越

单位: 浙江大学

时间限制: 400 ms

内存限制: 64 MB

代码长度限制: 16 KB

 

题目大意:首先给出26个大写字母的字符表示形式,然后给出一个句子。要把这个句子用上述规定好的字符形式表示。每个字符之间空一列,每个单词之间空一行。

数据结构与算法。首先明确好数据存储的结构,然后对数据进行处理,地基一定要打好,不能着急。

1.自己的解法

首先要分别存储26个字母的特殊形式,每个字母是一个[7][5]的矩阵,一共26个字母,[26][7][5],三维矩阵太复杂了,放弃。

直接采用二维数组,将template读进来,则A是0~6行,B是7~13行,以此类推。存储好之后,要标准化需要输出的单词。有两种分割的条件,遇到非A~Z的字符,分割;到最后一个字符,分割。

自己的方法,16分。

// ConsoleApplication4.cpp : 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include<cstdio>
#include<vector>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;


vector<string> word;
int temp[15];
void OutputLetter(string s){
	int idx = 0;
	for(int i = 0; i < s.size(); i++){
		int start = (s[i] - 'A') * 7 + 1;
		temp[idx++] = start;
	}
	for(int i = 0; i < 7; i++){
		for(int j = 0; j < idx; j++){
			cout<<word[temp[j]++];
			if(j != idx - 1)
				printf(" ");
		}
		if(i!=6)cout<<endl;
	}

}
int main(){
	int n = 26;
	string s;
	string target;
	word.push_back("111");
	for(int i = 1; i <= 182; i++)
	{
		cin>>s;
		word.push_back(s);
	}
	getchar();
	getline(cin, target);
	vector<string> wait_string;
	string tmp;
	int begin = 0;
	for(int i = 0; i < target.size(); i++){
		if(target[i] >= 'A' && target[i] <= 'Z'){
		}
		else{
			tmp = target.substr(begin, i - begin );
			wait_string.push_back(tmp);
			begin = i + 1;
		}
	}
	if(begin != target.size()){
		tmp = target.substr(begin);
		wait_string.push_back(tmp);
	}
	for(int i = 0; i < wait_string.size(); i++){
		OutputLetter(wait_string[i]);
		if(i != wait_string.size() - 1)
			printf("\n\n");
	}
	
	return 0;
}

 

 

2.大神的解法

字符串的处理,substr

#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <iostream>
using namespace std;
char letter[300][7][5];
void print(string str){
	for (int row=0; row<7; row++){
		for (int index=0; index<str.length(); index++){
			char let=str[index];
			for (int col=0; col<5; col++){
				printf("%c", letter[let][row][col]);
			}
			if (index!=str.length()-1) printf(" ");
		}
		printf("\n");
	}
}
int main(){
	for (int i='A'; i<='Z'; i++){
		for (int j=0; j<7; j++){
			for (int k=0; k<5; k++){
				scanf("%c",&letter[i][j][k]);
			}
			getchar();
		}
	}
	string str;
	getline(cin,str);
	vector<string> vt;
	int pre=0;
	int i=0;
	for (i=0; i<str.length(); i++){
		if (!(str[i]>='A' && str[i]<='Z')){
			string temp=str.substr(pre, i-pre);
			if (temp!="") vt.push_back(temp);
			pre=i;
			while (!(str[i]>='A' && str[i]<='Z')) {
				i++;
				pre++;
			}
		}
	}
	if (pre<str.length()) {
		string temp=str.substr(pre, str.length()-pre);
		vt.push_back(temp);
	}
	for (int i=0; i<vt.size(); i++){
		print(vt[i]);
		if (i!=vt.size()-1) printf("\n");
	}
}

3总结

  1. 学习cctype头文件。
  2. 不要怕程序上的麻烦,存储上的麻烦,逻辑清晰最重要,直接三维数组即可。
PAT-2019年冬季考试-甲级-7-1 Good in C (20分) 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 giv... 阅读详情

相关推荐

2019年12月7日PAT甲级满分题解与经验总结

PAT2019冬季甲级满分代码+占坑经验分享考题体验A题 题目+题解题目题解B题 题目+题解题目题解C题 题目+题解D题 题目+题解

彬糖的博客 1712

7-1 Good in C (20分)

坑壁的题目,比30分的还坑,分隔符可能是空格!所以一定用getline,而且居然用了三重循环。。。 #include <iostream> #include <vector> using namespace std; int main(){ vector<string> v[26], word; string s, temp; for(int i = 0;...

北冥有鱼 609

ArcGIS Pro 3.0 加载天地图WMTS服务,解决偏移问题的保姆级教程(附最新Key申请流程)

本文详细介绍了在ArcGIS Pro 3.0中精准加载天地图WMTS服务的全流程,包括最新Key申请流程、解决地图偏移问题的关键配置步骤以及常见问题排查方法。通过设置`esri`参数和统一坐标参考,确保地理数据与天地图底图精确匹配,提升GIS空间分析的准确性。

weixin_28713947的博客 309

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

这个题目有点搞人 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 gi...

dazhangyu97的博客 428

深入解析CycloneDDS跨域通信中的XML配置文件优化策略

本文深入解析了CycloneDDS跨域通信中XML配置文件的优化策略,重点介绍了网络接口配置、多播设置、性能调优参数及复杂场景下的配置案例。通过实战技巧和调试方法,帮助开发者在SoC环境中实现高效稳定的跨域通信,提升系统性能。

soda5的博客 689

Python语言在工业控制中的简单应用

在工业控制中,经常需要对采集到的数据进行分析和处理,Python的这些库可以简化这一过程。传统的工业控制系统多依赖于专用的控制硬件和软件,但随着技术的发展,开放性和灵活性成为了新的需求焦点。还有,Python社区活跃,提供了大量的开源代码和模块,这对于工业控制领域来说是一个巨大的资产。Python作为一种高级编程语言,因其简洁的语法、强大的库支持和广泛的社区资源而在工业界获得了快速的发展和广泛的应用。在工业控制领域,Python的应用日益增多,这得益于其跨平台性、脚本语言的灵活性以及与硬件设备交互的能力。

2303_78014702的博客 1722

7-1 Good in C (20分)

7-1Good in C(20分) 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 ...

~ 798

Windows安装ros2(Jazzy版本+win10/win11)-4.构建ros2结点

这个位置也是ros2搜索package以及搜索node的路径, 如果把构建好的可执行文件乱动位置的话就找不到节点了,当然如果复制一个可执行文件以及可执行文件-script.py文件, ros2也就会认为你有一个新的节点了,运行这个拷贝的可执行文件程序都是ok的。由于上一个文章给powershell7也增加了启动执行ros2的环境初始化文件local_setup.ps1, 所以我们也可以直接在vscode中运行节点, 此种方式没有经由ros2托管, 缺少其他ros2的附加能力。

weixin_48398592的博客 7114

PAT(甲级)2019年冬季考试 7-1 Good in C (20分) 7-2 Block Reversing (25分) 7-3 Summit (25分) 7-4 Cartesian Tree (

7-1Good in C(20分) 读题比较麻烦,实际不难,注意输出格式就可以了。 #include<cstdio> #include<vector> #include<iostream> #include<queue> #include<cmath> #include<string> #include<alg...

Ike_Lin的博客 398

Python 爬虫实战:就业市场趋势数据抓取与行业洞察

在当今竞争激烈的就业市场中,了解行业趋势和就业形势对于求职者、学生以及人力资源专业人士来说至关重要。通过获取和分析就业市场数据,我们可以深入了解不同行业的招聘需求、薪资水平、技能要求等关键信息,从而为职业规划和人才发展提供有力支持。

yansideyucsdn的博客 1407

【零基础学习CAPL】——CAN报文的发送(CRC——ChecSum值)

本章主要介绍带有CRC值的报文发送一般报文可使用CANoe的IG模块直接发送,但带有CRC值的报文就只能编写脚本进行发送,以下详细讲解在配合Panel面板情况下,如何进行带有循环冗余码的报文进行报文的发送。

LOVE135149的博客 1914

PAT甲级 2019年冬季12月7日 满分题解

写在前面 本次参加了2019年12月7日PAT冬季考试,考点在北京工业大学(土豪大学)。考试时间3个小时。一个半小时AK,其中第一道题提交了5次,第二道题提交2次,第三道题提交1次,第四道题提交1次,总排名好像是30。 这个报名是老早就报的,因为九月参加了一次,报名的时候发现北京赛区已满,只能去保定河北大学考试,成本着实有点高。 这学期其实很忙的,计网实践,算法,数据库,编译原理,操作系统,还有我...

冰冻三尺非一日之寒 1146

HFSS实战项目——微带一分四功分器

呕心沥血保姆级教程!!!!手把手教会你做功分器,史上最详细步骤!!!

2401_87464239的博客 2675

PAT(甲级)2019年冬季考试

PAT(甲级)2019年冬季考试 自我测试,两个小时多一点做完,感觉比较简单吧,第一道题一开始审错了,浪费好多时间,先做后面三道,一个小时多一点做完,然后又花了一个小时做第一道题。。。。 7-1 Good in C When your interviewer asks you to write “Hello World” using C, can you do as the following figure shows? Input Specification: Each input file conta

qq_42877165的博客 354

01 Python学习总结:Python简介及入门

Python 是一门高级编程语言,以其简洁、易读和强大的功能而广受欢迎。它适用于多种应用场景,包括 Web 开发、数据分析、人工智能、自动化脚本等。以下是 Python 的简介及入门知识总结,帮助你快速了解并开始学习 Python。

数据知道的博客 1万+

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

PAT(甲级)2019年冬季考试——题解+总结

PAT(甲级)2019年冬季考试 总结写在前头: 考了字符串、链表(伪链表)、图、树。考点比较均衡。 本次考试难度还行,需要较扎实的数据结构底子,对于字符串处理的技巧有一定的要求。 说句题外话,字符串是个重点,主要因为很多人会忽视字符串。2018-2019年的GPLT(团体程序设计天梯赛)的l1最后一题就是一道字符串处理,当时卡住了不知道多少人,但其实稍微做做字符串的题目之后就会发现,那题不过如此。这次PAT甲级的第一题也是不过如此,但很可惜,我当时也忽视了字符串的处理,错失甲满。。。 Good in

一个小渣渣的博客:) 1203

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

```scanf```无法读取空格,需要用```getline```读取空格 ```char```数组得开得大一点,这种字符串的题就应该用```string```做,不可能判断超时 最后的错误:```测试点4 运行时错误```(PAT给出的可能情况是:数组访问越界,) 数组越界,把每个数组开到```10000```即可(```测试点3:3分```) #include <bits/stdc++.h> using namespace std; char line[30][10][...

qq_41755143的博客 384

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

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

7-1Good in C(20分) 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...

蔡军帅 509

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 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

shshbdhsjjd的博客 228

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 do as the following figure shows? Input Specification: Each input file contains one test case. For each case...

faith_Dy的博客 420

PAT甲级 2017-2019 第一题 && 字符串专题

英语单词积累 PAT-2019年冬季考试-甲级-7-1 Good in C (20分) PAT甲级2019年秋季考试 1160 Forever (20 分) PAT(甲级)2019年春季考试 7-1 Sexy Primes (20 分) PAT(甲级)2018年冬季 1152 Google Recruitment (20分) substr(i,n)截取从i开始n个字符 stoi(n) 将字符n转化为整数 //c++11特性 PAT(A) – 2018.9.8秋季考试-甲级(1148) 7-1 Werew

0 347

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 E

0 323

2019冬季PAT甲级 题解和反思

非科班跨考, 本专业课考试也集中在12月份, 没有太多时间来复习PAT, 11月中旬把甲级题库155道粗略地刷完了一遍(在《算法笔记》的帮助下),然后从头开始二刷, 做了十几题以后觉得刷不完了, 加上其他考试的压力, 便搁置刷题计划, 考前一天将题库里面的关于图和树的题目的代码粗略地看了一遍,心想这次12月考试对明年的考研帮助也不大, 就当练手, 结果运气好, 考了满分。 这次的题目不难, 会写H...

xiaoh1999的博客 1084
上一篇: 总结与反思 - 12月7日冬季PAT甲级考试
下一篇: 2019.12.7PAT冬季考试第二题 - 7-2 Block Reversing (25分)
DedicateToAI
博客等级 码龄9年 6粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值