4 条题解
-
4
#include<stdio.h> int main() { int T,max,i; char s[1011]; scanf("%d",&T); while(T--) { scanf("%s",s); int a[26]={0}; //数组代表26字母序号 for(i=0;s[i]!='\0';i++) a[s[i]-'a']++; //字符串中s[i]字母对应序号自增 max=0; for(i=1;i<26;i++) //max作为下标,最大值的下标 if(a[i]>a[max]) max=i; printf("%c\n",max+'a'); //下标加‘a’还原该字母 } return 0; } -
1
#include<string.h> int num[10000],xx[10000]; int main() { int t; scanf("%d",&t); while(t--){ memset(num,0,sizeof num); memset(xx,0,sizeof xx); char a[10000]; int flag=0,ed; scanf("%s",a); int x=strlen(a); for(int i=0;i<x;i++){ num[i]=a[i]; xx[num[i]]++; } for(int i=0;i<10000;i++){ if(flag<xx[i]){ ed=i; flag=xx[i]; } } char q=ed; printf("%c\n",q); } return 0; } -
0
#include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
char s[1011];
scanf("%s", s);
int len = strlen(s);
int a[26] = { 0 };
char b[27] = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < len; i++)
{
for (int j = 0; j < 26; j++)
{
if (s[i] == b[j])
{
a[j]++;
}
}
}
int max = a[0];
int m = 0;
for (int i = 1; i < 26; i++)
{
if (max < a[i])
{
max = a[i];
m= i;
}
}
printf("%c\n", b[m]);
}
return 0;
}
-
0
#include<stdio.h> #include<string.h> int main() { int t; scanf("%d",&t); while(t--) { char str[1010]; scanf("%s",str); int count[26]={0};//26个字母 for(int i=0;i<strlen(str);i++) { count[str[i]-'a']++; //a-a=0,b-a=1,以此类推,count[0]就是a的个数,类推 } //已经知道每个字母的次数,求最多次的 int maxcount=0; for(int i=0;i<26;i++) { if(count[i]>maxcount) { maxcount=count[i]; } }//现在最多次的符号也知道了,该输出最小的那个了 for(int i=0;i<26;i++) { if(count[i]==maxcount) { printf("%c\n",'a'+i); break; } } } return 0; }
- 1
信息
- ID
- 186
- 时间
- 3000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- (无)
- 递交数
- 485
- 已通过
- 218
- 上传者