[백준 3507] Automated Telephone Exchange (C#, C++) - soo:bak
작성일 :
문제 링크
3507번 - Automated Telephone Exchange
설명
n - XX - YY = 0을 만족하는 행운 번호의 개수를 구하는 문제입니다.
XX와 YY는 각각 00부터 99까지 가능합니다.
접근법
두 수의 합이 n인 순서쌍을 모두 세면 됩니다.
0부터 99까지 이중 반복으로 완전탐색합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine()!);
var cnt = 0;
for (var i = 0; i <= 99; i++) {
for (var j = 0; j <= 99; j++) {
if (i + j == n) cnt++;
}
}
Console.WriteLine(cnt);
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) return 0;
int cnt = 0;
for (int i = 0; i <= 99; i++) {
for (int j = 0; j <= 99; j++) {
if (i + j == n) ++cnt;
}
}
cout << cnt << "\n";
return 0;
}