백준 #1105 팔
L과 R의 자릿수가 다르면 0, 같으면 앞 숫자부터 비교해서 같을 때의 8의 개수를 센다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;
int main() {
string L, R;
cin >> L >> R;
int eightCount = 0;
if(L.size() == R.size()) {
for(int i = 0; i < L.size(); i++) {
if(L[i] == R[i] && R[i] == '8') {
eightCount++;
}
if(L[i] != R[i]) {
break;
}
}
}
cout << eightCount;
return 0;
}
This post is licensed under CC BY 4.0 by the author.