ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PAT 1164 Good in C

2022-02-01 11:59:23  阅读:205  来源: 互联网

标签:1164 Good word int wor letters each PAT line


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

坑点

1.单词之间可能存在空格,所以要用getline不能用cin

2.单词之间,单词前,单词后存在多个字符。

3.输出不能有多余的空行,单词之间只能有一个空行。

#include<bits/stdc++.h>
using namespace std;
string s[30][10];
int main()
{
	for (int i = 0; i <= 25; ++i)
	{
		for (int j = 0; j <= 6; ++j)
		{
			cin >> s[i][j];
		}
	}
	string wor;
	getline(cin, wor);
	wor += " ";
	string word = "";
	int sz = wor.size();
	for (int i = 0; i < sz; ++i)
	{
		if (wor[i] <= 'Z' && wor[i] >= 'A')
		{
			word += wor[i];
		}
		else
		{
			if (i != 0 && (wor[i - 1] <= 'Z' && wor[i - 1] >= 'A'))
			{
				word += wor[i];
			}
		}
	}
	int pre = 0;
	sz = word.size();
	for (int i = 0; i < sz; ++i)
	{
		int x = word[i] - 'A';
		if (x <= 25 && x >= 0)
		{
			;
		}
		else
		{

			for (int j = 0; j <= 6; ++j)
			{
				for (int k = pre; k < i; ++k)
				{
					x = word[k] - 'A';
					cout << s[x][j];
					if (k != i - 1)cout << " ";
					else cout << endl;
				}
			}
			pre = i + 1;
			if (i != sz - 1)cout << endl;
		}
	}
}

 

标签:1164,Good,word,int,wor,letters,each,PAT,line
来源: https://blog.csdn.net/weixin_45840763/article/details/122763334

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有