-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.cpp
More file actions
47 lines (38 loc) · 1.01 KB
/
Copy path06.cpp
File metadata and controls
47 lines (38 loc) · 1.01 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
#include<bits/stdc++.h>
#include<String.h>
#include<iostream>
using namespace std;
string convert(string s, int numRows) {
int size = static_cast<int>(s.size());
// 当行数小于等于1 或 大于原串的size时不用转换
if (numRows <= 1 || numRows >= size) {
return s;
}
// 字符串数组, 装的是行的对应的字符串
vector <string> rowString(numRows);
int rowNum = 1;
// 向下读还是向上读的标志
int flag = 1;
for (int i = 0; i < size; ++i) {
rowString[rowNum-1] += s[i];
if (rowNum == numRows){
flag = -1;
}
if (rowNum == 1) {
flag = 1;
}
rowNum += flag;
}
string result;
for (int i = 0; i < numRows; ++i) {
result += rowString[i];
}
return result;
}
int main()
{
string s;
cin>>s;
cout<<convert(s,3);
cout<<"hello";
}