1 solutions

  • 0
    @ 2025-3-3 16:32:53

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){
    	string s;
    	int i,x;
    	getline(cin,s);
    	int a[200] = {0};
    	for(i = 0;i < s.size();i++){
    		x = s[i];
    		a[x]++;
    	}
    	
    	char c;
    	int max = 0;
    	for(i = 'z';i >= 'a';i--){
    		if(a[i] > max){
    			max = a[i];
    			c = i;
    		}
    	}
    	cout<<c<<endl;
    }
    
    
    

    Python :

    str1=input().strip()
    alist = list(set(str1))
    alist.sort(reverse=True)
    
    
    dic1=dict()
    for t in str1:
        if t not in dic1:
            dic1[t]=1
        else:
            dic1[t]=dic1[t]+1
    '''
    for key in dic1.keys():
        print(key,dic1[key])
    '''
    bb=sorted(dic1.items(), key=lambda kv: (-kv[1], -ord(kv[0])))
    '''
    for item in bb:
        print(item[0],item[1])
    '''
    print(bb[0][0])
    
    
    • 1

    Information

    ID
    10474
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By