반응형

문제 출처 :


https://www.acmicpc.net/problem/4246



알고리즘 분석 :


문제 해결에 필요한 사항

1. reverse 함수

2. 규칙


이 문제 자체가 'ㄹ' 방식으로 문자입력이 되어있다.


따라서 짝수번째줄은 항상 reverse를 통해 원래대로 바꿀 수 있다면, 쉽게 문제를 해결 할 수 있다.


그 짝수번째줄을 찾는것과 reverse를 하는 방법은 아래 코드에 수록되어있다.













소스 코드 : 


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
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int n;
    while (1)
    {
        scanf("%d"&n);
        if (n == 0)
            break;
 
        string str;
        cin >> str;
    
        int len = str.size();
 
        for (int mul = 1; n * mul < len; mul+=2)
            reverse(str.begin() + n * mul, str.begin() + n * (mul + 1));
 
        for (int start = 0; start < n; start++)
            for (int pos = start; pos < len; pos += n)
                cout << str[pos];
        cout << endl;
    }
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[2417번] 정수 제곱근  (0) 2017.09.11
[5012번] 불만 정렬  (2) 2017.09.09
[5214번] 환승  (2) 2017.09.03
[14425번] 문자열 집합  (0) 2017.08.29
[1535번] 안녕  (0) 2017.08.24