반응형
https://www.acmicpc.net/problem/13985
13985번: Equality
Print, on a single line, YES if the sum is correct; otherwise, print NO.
www.acmicpc.net
cin.getline(char형 변수, 입력받을 길이) 함수를 사용해서 풀었습니다.
char배열의 마지막에는 '\0'값이 들어갑니다 따라서 9글자를 입력받을 때는 10글자의 배열 길이의 char형 변수를 설정해 줘야 합니다.
1 2 3 4 5 6 7 8 9 10 11 | #include <iostream> #include <string> using namespace std; int main() { char a[10]; cin.getline(a,10); if ((a[0] - '0') + (a[4] - '0') == (a[8] - '0')) cout << "YES" << '\n'; else cout << "NO" << '\n'; } | cs |
'Algorithm' 카테고리의 다른 글
(C++) - 백준(BOJ) 2875번 : 대회 or 인턴 (0) | 2019.12.28 |
---|---|
(C++) - 백준(BOJ) 1009번 : 분산처리 (0) | 2019.12.28 |
(C++) - 백준(BOJ) 15700번 : 타일 채우기 4 (0) | 2019.12.21 |
(C++) - 백준(BOJ) 13752번 : 히스토그램 (0) | 2019.12.21 |
(C++) - 백준(BOJ) 14173번 : Square Pasture (0) | 2019.11.21 |