본문 바로가기

Competition/codeforces

Educational Codeforces Round 59 (Rated for Div. 2) A. Digits Sequence Dividing

A. Digits Sequence Dividing

https://codeforces.com/problemset/problem/1107/A


주어진 string을 2개 이상으로 분리하는데, k번째 항은 k-1번째 항보다 커야한다.

간단하게 2개로 분리한다고 하면, string[0]과 나머지를 대소비교 하면 된다.

3자리 이상일 때는 무조건 string[0]이 작으므로, string의 길이가 2일때만 주의하면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
 
int t, n;
string s;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> t;
    while (t--) {
        cin >> n >> s;
        if (s.length() == 2 && (s[0>= s[1])) {
            cout << "NO\n";
            continue;
        }
        cout << "YES\n2\n";
        cout << s[0<< " ";
        for (int i = 1; i < s.length(); i++cout << s[i];
        cout << '\n';
    }
    return 0;
}
cs