[SWEA] C++ 15230. 알파벳 공부(D3)

swb·2022년 11월 19일
0

SWEA

목록 보기
18/19

문제 바로가기

접근 방법

  1. 입력된 문자열 처음부터 알파벳(a~z)과 같은지 비교한다.
  2. 다르다면 다르기 전까지만 맞은 알파벳 숫자이다.
    - 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;
}
profile
개발 시작

0개의 댓글