-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.cpp
More file actions
72 lines (62 loc) · 1.73 KB
/
task1.cpp
File metadata and controls
72 lines (62 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// https://www.codingame.com/ide/puzzle/ascii-art
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int chooseLetter(char letter) {
int asciiNum = int(letter);
if (asciiNum <= int('Z') && asciiNum >= int('A') ||
asciiNum <= int('z') && asciiNum >= int('a')) {
if (asciiNum >= int('a')) return asciiNum - int('a');
else return asciiNum - int('A');
}
else return -1;
}
void writeRes(std::vector<std::vector<std::string>> letters, std::string t, int h) {
for (int i = 0; i < h; ++i) {
std::string row = "";
for (int j = 0; j < t.length(); ++j) {
int numLetter = chooseLetter(t[j]);
if (numLetter == -1) numLetter = letters.size() - 1;
row += letters[numLetter][i];
}
std::cout << row << std::endl;
}
return;
}
int main()
{
int l;
std::cin >> l; std::cin.ignore();
int h;
std::cin >> h; std::cin.ignore();
std::string t;
std::getline(std::cin, t);
auto n = t.length();
if (0 > l || l > 30) {
std::cout << "Invalid input";
return -1;
}
if (0 > h || h > 30) {
std::cout << "Invalid input";
return -1;
}
if (0 > n || n > 200) {
std::cout << "Invalid input";
return -1;
}
int countLetters;
std::vector<std::vector<std::string>> letters;
for (int i = 0; i < h; i++) {
std::string row;
std::getline(std::cin, row);
if (i == 0) {
countLetters = row.length() / l;
letters.resize(countLetters);
}
for (int j = 0; j < countLetters; ++j) {
letters[j].push_back(row.substr(l * j, l));
}
}
writeRes(letters, t, h);
}