forked from changqing16/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.cpp
More file actions
31 lines (29 loc) · 653 Bytes
/
6.cpp
File metadata and controls
31 lines (29 loc) · 653 Bytes
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
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
string convert(string s, int numRows)
{
int size = s.size();
char res[size + 1];
if (numRows == 1)
return s;
int len = 0;
for (int i = 0; i < numRows; i++)
{
for (int j = 0, k = i; k < size; j++)
{
res[len++] = s[k];
k += ((i == 0 || (j % 2 == 0)) && (i != numRows - 1)) ? 2 * (numRows - i - 1) : 2 * i;
}
}
res[size] = '\000';//c++的char机制呀
return res;
}
int main()
{
string s = "oqmsboagu";
string ans = convert(s, 9);
cout << ans << endl;
}