1 条题解

  • 0
    @ 2022-10-22 19:17:59

    C++ :

    #include<iostream>
    #include<cstring>
    using namespace std;
    const int N=1e3+5;
    char s[N][N];
    int vis[30];
    int main(){
    	int n,m,t;
    	t=0;
    	cin>>n>>m;
    	for(int i=0;i<n;i++){
    		cin>>s[i];
    	}
    	
    	memset(vis,0,sizeof(vis));
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			vis[s[i][j]-'A']++;
    		}
    	}
    	int ans,num;
    	ans=0;
    	for(int i=0;i<28;i++){
    		
    		if(ans<vis[i]){
    			ans=vis[i];
    			num=i;
    		}
    	}
    	
    	cout<<(char)(num+'A')<<endl<<ans;
    	return 0;
    }
    

    Python :

    # coding=utf-8
    n,m=map(int,input().split())
    list1=[]
    for i in range(n):
        s=input()
        list1.append(list(s))
    list2=[i for j in list1 for i in j]
    count_dict={}
    count_dict=count_dict.fromkeys(list2)
    list3=list(count_dict.keys())
    for i in list3:
        count_dict[i]=list2.count(i)
    count_dict=dict(sorted(count_dict.items(),key=lambda d:d[1],reverse=True))
    i=0
    for key,value in count_dict.items():
        if i<1:
            print(key)
            print(value)
            i+=1
            continue
        else:
            break
    
    • 1

    信息

    ID
    1635
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    17
    已通过
    9
    上传者