티스토리 뷰
출처 : https://www.hackerrank.com/challenges/encryption/problem
#include <bits/stdc++.h>
using namespace std;
string encryption(string s) {
string ans;
int L = s.length(), row = sqrt(L), col = row + 1, it = 0;
if (row*row == L) col -= 1;
if (row*col < L) row += 1;
char arr[10][10]; memset(arr, 0, sizeof(arr));
for (int i = 0; i < row; i++) {
for (int j = 0; j < col && it<L; j++) {
arr[i][j] = s.at(it);it++;
}
}
for (int j = 0; j < col; j++) {
for (int i = 0; i < row; i++) {
if (arr[i][j]) ans += arr[i][j];
}
if(j!=col-1)ans += " ";
}
return ans;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
string result = encryption(s);
fout << result << "\n";
fout.close();
return 0;
}
'알고리즘 > 기타' 카테고리의 다른 글
[HackerRank] Organizing Containers of Balls (0) | 2018.10.01 |
---|---|
[HackerRank] Queen's Attack II (0) | 2018.09.30 |
[HackerRank] Non-Divisible Subset (0) | 2018.09.30 |
[HackerRank] Forming a Magic Square (0) | 2018.09.30 |
[HackerRank] Extra Long Factorials (0) | 2018.09.28 |
- Total
- Today
- Yesterday
- 이차원 배열과 연산
- hackerrank
- DP
- 새로운 게임 2
- 백준
- 삼성
- STL
- 미세먼지 안녕!
- 게리맨더링 2
- 시간 복잡도
- 연구소 3
- 알고리즘
- SW Expert Academy
- 2018 KAKAO BLIND RECRUITMENT
- 팁
- SWEA
- 2018 카카오 블라인드 채용
- 17140
- 17837
- 17144
- boj
- scanf
- 17143
- DFS
- 입출력
- 트렌드
- string
- 17779
- 역량 테스트
- 17142
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |