PHP implementation protocol definition


1042. Character statistics (20)

time limit
400 ms
Memory limit
65536 kB
code length limit
8000 B
Judgment Program

Please write the program to find the most frequent English letters in a given text.

Input format:

Input a string with a length of no more than 1000 in one line. The string is composed of any visible characters and spaces in the ASCII code, which contains at least one English letter, which ends at the end of the car (the car is not included).

output format:

The English letters with the highest frequency of output and the number of times appeared in one line, and separated by spaces. If there is side by side, the letter with the smallest letter order is output. Statistically do not distinguish between lower and lowercase and output lowercase letters.

Input Sample example:

This is a simple TEST.  There ARE numbers and other symbols 1&2&3...........

output sample:

e 7

Thought: and
[The Beauty of Programming -02] String contains problems

Efficient solution method is done according to the principle of the ASCII code, but it is not considered here, so the size of the array is 27. Note: You have to read the input with gets (). Because you need to read it all.

char s[1002];
int main()
	//freopen("E://input.txt", "r", stdin);
		int count[27];
		memset(count, 0, sizeof(count));
		for(int i = 0; i < strlen(s); i ++)
			if(s[i] >= 'A' && s[i] <= 'Z')
				count[s[i]-'A'] ++;
			if(s[i] >= 'a' && s[i] <= 'z')
				count[s[i]-'a'] ++;
		int max = 0, index = 0;
		for(int i = 0; i < 27; i ++)
			if(count[i] > max)
				max = count[i];
				index = i;
		printf("%c %d\n", index+'a', max);
	return 0;


Related Posts

Android open source animation library Nineoldandroids

icon understands the convolutional calculus calculation, inverse convolutional calculation, TensorFlow, TF.NN.CONV2DTRANSPOSE, CONV2DSLOWBACKPROPINPUT: SIZE of OutBackprop Doesnianzuethan

Vue-Element Project Real Combat Commodity Management System Fantasy Light

Remove the two -dimensional code in the PHP Testing Network -Google Browser Plug -in

PHP implementation protocol definition

Random Posts

Line segment tree build tree index The

Weight attenuation (regularization)

FZU2203-Competition-10.1 Training Tournament

[One of the COCOS2D-X] V2.2.0 version of the development environment configuration

web automated test keyboard operation event