1157번 - 단어 공부
#include
using namespace std;
int main() {
string in_alpha; // 입력받을 영어
cin >> in_alpha;
if (in_alpha.length() <= 1000000) {
int in_alpha_toi; // 입력받은 값 아스키 코드로 변환할 변수
char in_alpha_toi_toc; // 변수값을 문자열로 변환할 변수
int count_alpha[26] = {0}; // 카운트값 저장할 변수
int result_count; // 최댓값 최솟값 비교
int result; // 결론적으로 자주 쓰인 영어
for (int i = 0; i < in_alpha.size(); i++) {
in_alpha_toi = in_alpha[i];
if (in_alpha_toi >= 65 && in_alpha_toi <= 90)
in_alpha_toi -= 65;
if (in_alpha_toi >= 97 && in_alpha_toi <= 122)
in_alpha_toi -= 97;
count_alpha[in_alpha_toi] += 1;
}
result_count = count_alpha[0];
for (int i = 0; i < 25; i++) {
if (count_alpha[i+1] != 0) {
if (result_count < count_alpha[i + 1]) {
result_count = count_alpha[i +1];
result = i+1;
else if (result_count == count_alpha[i + 1]) {
result = 100;
break;
else if(result_count > count_alpha[i+1]) {
result = i;
in_alpha_toi_toc = result + 65;
if (result == 100)
cout << "?" << endl;
cout << in_alpha_toi_toc << endl;
return 0;
반례)
abcc
답:
C
댓글을 작성하려면 로그인해야 합니다.
yjh990219 1년 전
#include
#include
using namespace std;
int main() {
string in_alpha; // 입력받을 영어
cin >> in_alpha;
if (in_alpha.length() <= 1000000) {
int in_alpha_toi; // 입력받은 값 아스키 코드로 변환할 변수
char in_alpha_toi_toc; // 변수값을 문자열로 변환할 변수
int count_alpha[26] = {0}; // 카운트값 저장할 변수
int result_count; // 최댓값 최솟값 비교
int result; // 결론적으로 자주 쓰인 영어
for (int i = 0; i < in_alpha.size(); i++) {
in_alpha_toi = in_alpha[i];
if (in_alpha_toi >= 65 && in_alpha_toi <= 90)
in_alpha_toi -= 65;
if (in_alpha_toi >= 97 && in_alpha_toi <= 122)
in_alpha_toi -= 97;
count_alpha[in_alpha_toi] += 1;
}
result_count = count_alpha[0];
for (int i = 0; i < 25; i++) {
if (count_alpha[i+1] != 0) {
if (result_count < count_alpha[i + 1]) {
result_count = count_alpha[i +1];
result = i+1;
}
else if (result_count == count_alpha[i + 1]) {
result = 100;
break;
}
else if(result_count > count_alpha[i+1]) {
result = i;
}
}
}
in_alpha_toi_toc = result + 65;
if (result == 100)
cout << "?" << endl;
cout << in_alpha_toi_toc << endl;
}
return 0;
}