我是靠谱客的博主 鲤鱼犀牛,这篇文章主要介绍【UJN-寒假练练练】新年快乐-2-进制转换与字符串_S - Number of letters,现在分享给大家,希望可以做个参考。

S - Number of letters

Find out the letter that occurs the most times in a string that consistes
of 'a'-'z'.

Input

Line 1: an integer N, indicates the number of test case

Line 2, 4, 6...2N: a string consistes of 'a'-'z', of which the size is from 1 to 1000 inclusive

LIne 3, 5, 7...2N-1: blank line

Output

Output N lines corresponding N strings of inputs.

Each line contains a letter that occurs the most times in the corresponding string and a number that is the time of occurence, seperated by a blank space.

Sample Input

复制代码
1
2
3
4
5
2 abbccc adfadffasdf

Sample Output

复制代码
1
2
3
c 3 f 4

题意:

找到对应字符串中出现次数最多的小写字母

题解:

01 map[26]={"abcdefghijklmnopqrstuvwxyz"}; 进行映射

02 (不用映射也行)用下标做一个加法

03 小心输入字符串时中间的空行

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// S - Number of letters #include<stdio.h> #include<string.h> int main() { int n,i,count,pos; int map[26]; char str[1005],ch; // 老规矩 %*c 吃回车 scanf("%d%*c",&n); count=0; while( count<n ) { gets( str ); // 跳过空行 if( str[0]=='' ) continue; count++; memset( map,0,sizeof( map ) ); // 计数 for( i=0;str[i];i++ ) { map[ str[i]-'a' ]++; } pos=0; ch='a'; // 找出现次数最多的小写字母 for( i=1;i<26;i++ ) { if( map[pos]<map[i] ) { // 用下标做加法 也能找到对应小写字母 pos=i; ch='a'+i; } } printf("%c %dn",ch,map[pos]); } return 0; }

个人见解 酌情采纳.

最后

以上就是鲤鱼犀牛最近收集整理的关于【UJN-寒假练练练】新年快乐-2-进制转换与字符串_S - Number of letters的全部内容,更多相关【UJN-寒假练练练】新年快乐-2-进制转换与字符串_S内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部