본문 바로가기
Computer Science

APS 기본 실습문제 String / string

by OKOK 2018. 12. 13.

1. 2개의 길이를 구하는 함수

2. 일치하는 부분을 찾는 것

3. 오엔으로 계속 나아가는 가면서 찾음

4. 확실함?

5. 이렇게 해도 순서가 빠른 편임 


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
int main(void)
{
    freopen("input.txt""r", stdin);
    setbuf(stdout, NULL);
 
    int test_case;
    int T = 10;
 
    for (test_case = 1; test_case <= T; ++test_case)
    {
        int tc;
        int match = 0;
        int p_len = 0;
        int t_len = 0;
        char p[10]; // 주어짐
        char t[1000]; // 주어짐
 
        scanf("%d\n"&tc);
 
        scanf("%s", p);
        scanf("%s", t);
 
        while (p[p_len] != '\0') {
            //        printf("%c",p[p_len]); 
            p_len = p_len + 1;
        }
        while (t[t_len] != '\0') {
            //        printf("%c",t[t_len]); 
            t_len = t_len + 1;
        }
        //           printf("%c",t[t_len+1]); 
 
        int i = 0int j = 0;
        while (t[i] != '\0') {
            if (t[i] != p[j]) {
                i = i - j;
                j = -1;
 
            }
            if (j == p_len - 1) {
                //       printf("%d %d\n", i,j);
                match++;
                j = -1;
 
            }
            ++i;
            ++j;
        }
        //       printf("%d %d %d", t_len, i, j);
        printf("#%d %d\n", test_case, match);
    }
    return 0;//정상종료시 반드시 0을 리턴해야합니다.
 
}
 
cs


댓글