문제 바로가기
접근방법
- 모음이 발견되면 지워준다.
- 또는 모음이 아닌 문자만 출력한다.
풀이1 (배열에 모음)
#include <iostream>
#include <string>
using namespace std;
int test_case, k, j, length;
char arr[5] = { 'a','e','i','o','u' };
string str;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> test_case;
for (int i = 1; i <= test_case; i++) {
cin >> str;
j = 0, k = 0;
length = str.size();
while (j != length) {
length = str.size();
if (str[j] == arr[k]) {
str.erase(j,1);
k = 0;
}
else {
k++;
}
if (k == 5) {
k = 0;
j++;
}
}
cout << "#" << i << " " << str << "\n";
}
return 0;
}
풀이2 (간결)
#include <iostream>
using namespace std;
int main() {
int test_case, T;
cin >> T;
string str;
string answer = "";
for(test_case = 1; test_case <= T; test_case++) {
cin >> str;
for(int i = 0; i < str.length(); i++) {
if ( str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u') {
answer += str[i];
}
}
cout << "#" << test_case << " " << answer << "\n";
answer = "";
}
return 0;
}