기술 블로그

1120번 문자열 본문

알고리즘 문제/BOJ

1120번 문자열

parkit 2018. 12. 29. 13:50
728x90
반응형

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





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
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
 
using namespace std;
 
string A, B;
 
int main(void)
{
    cin >> A;
    cin >> B;
 
    int diff = 0;
 
    if (A.length() == B.length())
    {
        for (int i = 0; i < A.length(); i++)
        {
            if (A.at(i) != B.at(i)) ++diff;
        }
    }
    else
    {
        diff = 100;    
 
        for (int i = 0; i < B.length(); i++)
        {
            int a = 0, b = i, d = 0;
 
            if (i + A.length() > B.length()) break;
 
            while (a < A.length())
            {
                if (A.at(a) != B.at(b)) ++d;
                        
                ++a;
                ++b;            
            }
            
            diff = min(diff, d);
        }
    }
 
    printf("%d\n", diff);
 
    return 0;
}
cs


728x90
반응형

'알고리즘 문제 > BOJ' 카테고리의 다른 글

4179번 불!  (0) 2018.12.30
1019번 책 페이지  (0) 2018.12.29
10448번 유레카 이론  (0) 2018.12.29
7568번 덩치  (0) 2018.12.29
1213번 팰린드롬 만들기  (0) 2018.12.29