当前位置:网站首页>Pat class B 1109 good at C (detailed)
Pat class B 1109 good at C (detailed)
2022-07-27 13:19:00 【Curz crisp】
When you are asked by the interviewer to use C Write a “Hello World” when , Do you have the ability to write one out as shown in the figure below ?

Input format :
The input first gives 26 English capital letters A-Z, One for each letter 7×5 Of 、 from C and . The matrix formed by . Finally, give a sentence in one line , End with a carriage return . A sentence consists of several words ( Each contains no more than 10 Consecutive capital letters ) Composed of , Words are separated by any non capitalized English letter .
The title is guaranteed to give at least one word .
Output format :
For each word , Output each letter in a row in matrix form , There is a column of spaces between the letters . There must be no extra spaces at the beginning and end of the word .
There must be a space between two adjacent words . There must be no extra blank lines at the beginning and 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.
This is a slightly complicated string processing problem , Take more time to get familiar with this practice .
AC Code :
#include<bits/stdc++.h>
using namespace std;
string alpha[66][66]; // Read in 26 Letters
string ans[6666]; // Used to output results , Pay attention to the space
string targetStr; // Target string
int main(){
for(int i = 0; i < 26; i++) //26 Letters
for(int j = 0; j < 7; j++) // Each letter has 7 That's ok , So I have to save 7 That's ok
getline(cin, alpha[i][j]); // Save line by line
getline(cin, targetStr); // Save the target string
int idx = 0; // The subscript of the result array
int t = 0; // Used to wrap lines
bool f = false; // Determine whether the next digit is a letter
for(int i = 0; i < targetStr.length(); i++){
if(targetStr[i] >= 'A' and targetStr[i] <= 'Z'){ // If it's a letter
for(int j = 0; j < 7; j++){ // Read a letter , Because a letter has 7 That's ok , So read it 7 Time
ans[idx] += alpha[targetStr[i] - 'A'][j]; //[s[i] - 'A'] The range of the number obtained is 0 To 26, Just corresponding to the letters ;[j] Represents the... Of the letter that will be read j There is a corresponding res in
if(targetStr[i + 1] <= 'Z' and targetStr[i + 1] >= 'A') ans[idx] += " "; // If the next letter in the target string is still a letter , Just add a space ( Because there are spaces between every letter in the result )
++idx; //ans The subscript idx One back , Continue to access the same letter 7 The next line in the line
}
f = true; // It means that the current is a letter , Mark the , Line breaks will work after reading a word
}
else if(f == true){ // Can get here , Indicates that the current character is not a letter , It means that you have finished reading a word
f = false; // Reset
t += 7; //t+=7 representative res Move the subscript back 7 position , Equivalent to reading a word and then wrapping
}
idx = idx % 7 + t; // The same word is on the same line , therefore idx The subscript of must be remainder , Otherwise, when outputting, the letters of the same word will run down
}
for(int i = 0; ans[i].size() != 0; i++){ //ans Output line by line from the beginning , Until you encounter empty
if(i % 7 == 0 and i != 0) cout << "\n"; // Read a line of words , To wrap
cout << ans[i] << "\n"; // Imagine being a printer , Output line by line from top to bottom , So it's a new line
}
return 0;
}
边栏推荐
- Will saffron become a safe and effective natural therapy for patients with arthritis?
- Wfuzz, a test tool that can blur everything that can be blurred
- 绝对定位
- Amd adrenalin 22.7.1 driver update: double the performance of OpenGL and support Microsoft win11 22h2 system
- Multi activity disaster recovery construction after 713 failure of station B | takintalks share
- 延迟队列DelayQueue性能测试
- 程序员培训学习后好找工作吗
- How to ask questions on the road for the first time - necessary skills for self-study (with live playback)
- 正向预查和反向预查
- How can the top 500 enterprises improve their R & D efficiency? Let's see what industry experts say!
猜你喜欢

Initializing database error after reinstalling MySQL

multi-table query

初探基于OSG+OCC的CAD之任意多个子模型进行netgen以及gmsh网格划分

Error: the source of the existing CacheManager is: urlconfigurationsource

GAN:生成对抗网络 Generative Adversarial Networks

「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader

BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (

AMD Adrenalin 22.7.1 驱动更新:OpenGL 性能翻倍,支持微软 Win11 22H2 系统

Zhongke Lanxun fell 30% on the first day of listing: Huang Zhiqiang, 60, started a company with a market value of 7.7 billion

From the perspective of it, the CIO of B2B industry talks about how to change from "cost center" to "growth center"?
随机推荐
JNI程序如何进行参数传递
Eccv2022 | Ru & Google proposed to use clip for zero shot target detection!
pg同步多张数据表至mysql 有办法简化配置吗?
500强企业如何提升研发效能?来看看行业专家怎么说!
JS single thread understanding notes - Original
轮播图
Nodejs body parser middleware processes post form data of type multipart / form data, and req.body cannot receive data
视频游戏沉迷行为研究综述
feign client三个客户端的自动装配
clear
元素的层级
[cute new solution] Fibonacci sequence
@Simple understanding and use of conditionalonproperty
Detail throw and throws
@Simple use of conditional
相对定位
Xposed+fdex2 app shelling (black cat complains about app shelling)
W3School导航栏练习
Qt优秀开源项目之十三:QScintilla
What should I do if I can't see any tiles on SAP Fiori launchpad?