백준 #1105 팔
L과 R의 자릿수가 다르면 0, 같으면 앞 숫자부터 비교해서 같을 때의 8의 개수를 센다.
#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;
}
Comments