문제 바로가기
접근 방법
- 입력된 문자열 처음부터 알파벳(a~z)과 같은지 비교한다.
- 다르다면 다르기 전까지만 맞은 알파벳 숫자이다.
- D3 중에 거의 가장 쉬웠던 문제
풀이
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <math.h>
using namespace std;
int tc, T, cnt;
string str;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
int main() {
cin >> T;
for (tc = 1; tc <= T; tc++) {
cin >> str;
cnt = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] != alphabet[i])
break;
else
cnt++;
}
cout << "#" << tc << " " << cnt << "\n";
}
return 0;
}