Baekjoon 1157 문제
2022. 5. 2. 00:52ㆍBaekjoon
진짜 미쳐버릴껏같다 이문제를 4시간동안 봤다. ㅠㅠ
#include <stdio.h>
int main()
{
char arr[1000001] = { ' ' }; //
int index_count [26] = { 0 }; //
int index = 0; // 문자열 저장할려고 만든 인덱스값
int max = 0; // 가장 많이나온값
char maxindex = 0; // 가장 많이나온 문자
for (int i = 0; arr[i] != '\0'; i++)
{
if (arr[i] >= 97 && arr[i] <= 122) // 소문자 대문자로변환 인덱스쪽에 -65 하여 0을 맞춘다
{
arr[i] -= 32;
}
index = arr[i] - 65; // alpha 문자열 0부터 저장하기위해 | a - > A 0 식으로 저장해야한다.
index_count[index]++; // 0부터 내가친 문자까지 저장 | b - > B 1
if (index_count[index] == max) //
{
maxindex = '?';
}
else if (index_count[index] > max) // 가장 많이나온값 저장
{
max = index_count[index]; //
maxindex = arr[i];
}
}
printf("%c", maxindex);
}
'Baekjoon' 카테고리의 다른 글
Stack 1,2,3,4 (0) | 2022.06.22 |
---|---|
Baekjoon (0) | 2022.05.01 |
Baekjoon 4344 (0) | 2022.05.01 |
Baekjoon 8958번 (0) | 2022.04.30 |
2675번 (0) | 2022.04.29 |