반응형

문제 출처 :


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



알고리즘 분석 :


문제 해결에 필요한 사항

1. 구현


입력을 getline으로 받아주고 p가 len보다 작을때까지 반복해주며 현재 p가 공백 즉, 떨어질 경우 break를 해주면 된다.


그 후 계속 다음줄을 받아주며 반복해주면 된다.


출력은 0번부터 p가 시작하니 p + 1을 해준다.





소스 코드 : 


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
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    while (1)
    {
        int n;
        scanf("%d"&n);
 
        if (!n) 
            break;
 
        getchar();
 
        int p = 0;
        for (int i = 0; i < n; i++)
        {
            string str; 
            getline(cin, str);
 
            int len = str.size();
            while (p < len)
            {
                if (str[p] == ' '
                    break;
                p++;
            }
        }
        printf("%d\n", p + 1);
    }
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus

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
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int n;
int main() {
    while (1) {
        scanf("%d"&n);
        if (n == 0break;
        getchar();
        int idx = 0;
        for (int i = 0; i < n; i++) {
            string str;
            getline(cin, str);
            int len = str.size();
            for (; idx < len; idx++) {
                if (str[idx] == ' ') {
                    break;
                }
            }
        }
        printf("%d\n", idx + 1);
    }
    return 0;
}
cs


반응형