题目:
输入样式
..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!
题解:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
string key; //记录每行字符串
vector<string>t; //记录全部
string word; //要输出的句子
//初始化
for (int i = 0; i < 26; i++) //字母数量
{
for (int j = 0; j < 7; j++) //一个字母由7行字符串组成
{
cin >> key;
t.push_back(key);
}
}
getline(cin, word); //获取回车
getline(cin, word);
//选出单词
string word_p; //筛选出单词
//去除前面的多余字符
for (int i = 0; i < word.size(); i++)
{
if (isupper(word[i]))
{
word = word.substr(i);
break;
}
}
vector<string>p; //存储单词
for (int i = 0; i < (int)word.size();i++)
{
//只输出字母
if (isupper(word[i]))
{
word_p += word[i];
}
//遇到不符合的字符则找出了一个单词
if (!isupper(word[i]) || i == (int)word.size() - 1)
{
p.push_back(word_p);
word_p.clear(); //清空
//跳过多余字符
while (!isupper(word[i+1]) && i+1 < (int)word.size())
{
i++;
}
}
}
//输出
for (int i = 0; i < (int)p.size(); i++) //单词数
{
for (int j = 0; j < 7; j++) //控制单词的每一行
{
int count = 0;
for (int k = 0; k < (int)p[i].size(); k++) //控制一行中每个字母的部分输出
{
count++;
//第一个单词前没有空格
if (count != 1)
{
cout << ' ';
}
cout << t[(p[i][k] - 'A') * 7 + j];
}
cout << endl;
}
if (i != (int)p.size() - 1)
{
cout << endl;
}
}
return 0;
}
标签:...,PAT,..,int,....,乙级,CCCC,word,刷题
From: https://blog.csdn.net/2301_79580018/article/details/139564069