fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8.  
  9. int main(void)
  10. {
  11. string sentence;
  12. getline(cin, sentence);
  13. int alphabet[26] = { 0 };
  14. int temp[26] = { 0 };
  15. for (int i = 0; sentence[i] !='\0'; i++)
  16. {
  17. if (sentence[i] != ' ') //띄어쓰기가 아니라면
  18. {
  19. alphabet[sentence[i] - 'a']++; //그 알파벳의 해당 인덱스에 저장된 숫자를 1씩 증가 (a는 0번째 인덱스)
  20. temp[sentence[i] - 'a']++;
  21. }
  22. }
  23. sort(alphabet, alphabet + 26); //최다 쓰인 횟수가 몇번인지 알기 위해 조사
  24. for(int k = 0; k < 26; k++)
  25. {
  26. if (temp[k] == alphabet[25]) //최다인 25번째 인덱스안에 저장된 숫자만큼 쓰였으면 출력
  27. cout << char(k + 'a'); //아스키코드를 이용해서 인덱스에 숫자 97을 더한 문자 출력
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 4376KB
stdin
b
b
a
a
c
stdout
b