当前位置:网站首页>Pat grade A - 1164 good in C (20 points)
Pat grade A - 1164 good in C (20 points)
2022-07-03 22:16:00 【White speed Dragon King's review】
subject
give A-Z And a sentence , Output word segmentation sentences in matrix form
Ideas
Three dimensional array saves every letter
Then splice it together
Pit point
The space may also be seperator
use getchar()+getline() Get the whole row
src:
#include<bits/stdc++.h>
using namespace std;
// Every English letter is 7 * 5 One of the matrix
char word[26][7][5];
int main() {
for(int i = 0; i < 26; i++) {
for(int j = 0; j < 7; j++) {
for(int k = 0; k < 5; k++) {
cin >> word[i][j][k];
}
}
}
string sentence;
getchar();
// The space may also be seperator
getline(cin, sentence);
vector<string> v;
int left = 0;
int right = 0;
while(left < sentence.size()) {
if(sentence[left] < 'A' || sentence[left] > 'Z') {
++left;
right = left;
}
else {
while(right < sentence.size() && sentence[right] >= 'A' && sentence[right] <= 'Z')
right++;
v.push_back(sentence.substr(left, right - left));
left = right;
}
}
//cout << v[1] << endl;
for(int i = 0; i < v.size(); i++) {
char ans[7][200];
int wordLen = v[i].size();
for(int j = 0; j < wordLen; j++) {
int index = v[i][j] - 'A';
for(int p = j * 6; p < (j + 1) * 6; p++) {
for(int q = 0; q < 7; q++) {
if(p == (j + 1) * 6 - 1) ans[q][p] = ' ';
else {
ans[q][p] = word[index][q][p % 6];
}
}
}
}
// Output the result of this line
for(int q = 0; q < 7; q++) {
for(int j = 0; j < wordLen * 6 - 1; j++) {
cout << ans[q][j];
}
cout << endl;
}
if(i != v.size() - 1) cout << endl;
}
return 0;
}
summary :
And manually split
cpp It's really inconvenient
边栏推荐
- 2 spark environment setup local
- Yyds dry goods inventory Spring Festival "make" your own fireworks
- [dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
- Implementation principle of inheritance, encapsulation and polymorphism
- 油猴插件
- IPhone development swift foundation 08 encryption and security
- Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
- BUUCTF,Misc:LSB
- Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
- string
猜你喜欢
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Functions and differences between static and Const
Dahua series books
Teach you how to run two or more MySQL databases at the same time in one system
STM32 multi serial port implementation of printf -- Based on cubemx
Why use pycharm to run the use case successfully but cannot exit?
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
Control loop of program (while loop)
随机推荐
Teach you how to install aidlux (1 installation)
gslb(global server load balance)技術的一點理解
Plug - in Oil Monkey
Rest reference
Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
Mysql database - Advanced SQL statement (I)
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
How PHP adds two numbers
Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
Go language slice interview real question 7 consecutive questions
Remember the experience of automatically jumping to spinach station when the home page was tampered with
Asynchronous artifact: implementation principle and usage scenario of completable future
Redis single thread and multi thread
[golang] leetcode intermediate - alphabetic combination of island number and phone number
Cognitive fallacy: Wittgenstein's ruler
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
Data consistency between redis and database