Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. void converttolower(char s[]){
  4.     for(int i=0; i<strlen(s); i++){
  5.         if(s[i] <=90 && s[i] >= 65){
  6.             s[i] += 32;
  7.         }
  8.     }
  9. }
  10. int main(){
  11.     int n;
  12.     char s[100000];
  13.     scanf("%d",&n);
  14.     char ch;
  15.     scanf("%c",&ch);
  16.     while(n--){
  17.         int count[1000];
  18.         int maxasci[1000];
  19.         for(int i=0; i<1000;i++){
  20.             count[i] = 0;
  21.             maxasci[i] = 0;
  22.         }
  23.        
  24.         fgets(s,1000,stdin);
  25.         int len = strlen(s);
  26.         s[len-1] = 0;
  27.         len = strlen(s);
  28.         converttolower(s);
  29.         for(int i=0; i<len; i++){
  30.             if(s[i] != ' ')
  31.                 count[s[i]]++;
  32.         }
  33.         int max = 0;
  34.        
  35.         int ind =0;
  36.         for(int i=0;i<len; i++){
  37.             if( count[s[i]] > max){
  38.                 max = count[s[i]];
  39.             }
  40.         }
  41.         for(int i=0; i<len; i++){
  42.             if(count[s[i]] == max){
  43.                 maxasci[s[i]] = s[i];
  44.             }
  45.         }
  46.         for(int i=1; i<=128; i++){
  47.             if(i == maxasci[i]){
  48.                 printf("%c",maxasci[i]);
  49.             }
  50.         } printf("\n");
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement