반응형

6679번 문제 : 싱기한 네자리 숫자

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


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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
using namespace std;
 
bool Check(int num)
{
    int a = 0, b = 0, c = 0;
    int a_sum = 0, b_sum = 0, c_sum = 0;
    a = num;
    b = num;
    c = num;
    
    while (a > 0)
    {
        a_sum += a % 10;
        a /= 10;
    }
 
    while (b > 0)
    {
        b_sum += b % 12;
        b /= 12;
    }
 
    while (c > 0)
    {
        c_sum += c % 16;
        c /= 16;
    }
 
    if (a_sum == b_sum && a_sum == c_sum && a_sum == b_sum)
        return true;
    else
        return false;
}
 
int main()
{
    for (int i = 1000; i < 10000; i++)
    {
        if (Check(i))
            cout << i << endl;
    }
 
    return 0;
}
cs



1051번 문제 : 숫자 정사각형

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


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
57
58
59
60
61
#include <iostream>
#include <string>
 
using namespace std;
 
int max_x, max_y;
int matrix[100][100= { 0, };
int index = 0;
 
bool CheckSquare(int x, int y)
{
    if (x >= 0 && x < max_x - index && y >= 0 && y < max_y - index)
    {
        if (matrix[x][y] == matrix[x][y + index] && matrix[x][y] == matrix[x + index][y] && matrix[x][y] == matrix[x + index][y + index])
        {
            return true;
        }
    }
 
    return false;
}
 
 
int main()
{
    cin >> max_x >> max_y;
 
    for (int i = 0; i < max_x; i++)
    {
        string input;
        cin >> input;
        for (int j = 0; j < max_y; j++)
        {
            matrix[i][j] = input[j] - '0';
        }
    }
 
    int index_max = min(max_x, max_y);
    int max_squareSize = 0;
 
    while (index < index_max)
    {
        for (int i = 0; i < max_x; i++)
        {
            for (int j = 0; j < max_y; j++)
            {
                if (CheckSquare(i, j))
                {
                    max_squareSize = (index + 1* (index + 1);
                    break;
                }
            }
        }
 
        index++;
    }
 
    cout << max_squareSize << endl;
 
    return 0;
}
cs


메모:

-index =0부터 시작해야함 그러지 않으면

1 1

1

예외 발생 정답:1 (오답: 0)

반응형

'C++ Algorithm > 백준 알고리즘 문제 풀이' 카테고리의 다른 글

우선순위 큐  (0) 2019.08.27
트리 사용하기  (0) 2019.04.29
그리디 알고리즘  (0) 2019.04.28
동적 계획법 기초  (0) 2019.04.08
그래프(DFS, BFS)  (0) 2019.04.04

+ Recent posts