본문 바로가기

Coding/백준 온라인 저지 (Baekjoon Online Judge)

백준 온라인 저지(Baekjoon Online Judge) - 2204 : 도비의 난독증 테스트

https://www.acmicpc.net/problem/2204

 

2204번: 도비의 난독증 테스트

꿍은 도비에게 영어단어들을 제시한 후 어떤 단어가 대소문자를 구분하지 않고 사전순으로 가장 앞서는지 맞추면 양말을 주어 자유를 얻게해준다고 하였다. 하지만 인성이 좋지 않은 꿍은 사실

www.acmicpc.net

 

#include <iostream>
#include <string>
using namespace std;

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)
			break;
		string* word = new string[n];
		string* temp = new string[n];

		for (int i = 0; i < n; i++) {
			cin >> word[i];
			cin.ignore();

			temp[i] = word[i];

			for (int j = 0; j < temp[i].length(); j++) {
				if (temp[i][j] >= 97 && temp[i][j] <= 122)
					temp[i][j] -= 32;
			}

		}

		string smallest = temp[0];
		int index = 0;

		for (int i = 1; i < n; i++) {
			if (smallest.compare(temp[i]) > 0) {
				smallest = temp[i];
				index = i;
			}
		}

		cout << word[index] << endl;
	}
}