본문 바로가기
Computer Science

문자열 변경하기

by OKOK 2019. 1. 31.

1. a의 위치 찾기

2. 변경시 가능한가

3. 안되는 경우 찾아보기

4. 반례 찾기 


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
#include <stdio.h>
 
#define MAX 100001
char S[MAX];
char T[MAX];
 
int my_abs(int a)
{
    if (a < 0return -a;
    return a;
}
 
int main()
{
    freopen("input.txt""r", stdin);
    int t;
    scanf("%d "&t);
    for (int test_case = 1; test_case <= t; test_case++
    {
        scanf("%s ", S);
        scanf("%s ", T);
 
        int S_pt = -1;
        int T_pt = -1;
        long long ans = 0;
 
        do
        {
            while (S[++S_pt] != 'a' && S[S_pt] != 0); // 첫 번째 문자열 a 위치 찾기
            while (T[++T_pt] != 'a' && T[T_pt] != 0); // 두 번째 문자열 a 위치 찾기
            ans += my_abs(S_pt - T_pt); // 두 개의 위치의 차이를 더하기
        } while (S[S_pt]); // S_pt가 끝인가? // -1 이 나오는 경우는?
 
        printf("#%d %lld\n", test_case, ans);
    }
    return 0;
}
cs

 


'Computer Science' 카테고리의 다른 글

혜리의 숫자 나누기  (0) 2019.02.01
현주의 상자 바꾸기  (0) 2019.02.01
중호와 세 소수  (0) 2019.01.31
정곤이의 단조 증가하는 수  (0) 2019.01.31
삼성시의 버스 노선  (0) 2019.01.31

댓글