1319 word statistics

Source: Internet
Author: User
Description

Given a segmentArticle, Each line cannot exceed 1000 characters, count the frequency of each word in the article, ignore case differences.

Note: different forms of words are considered different words, and even characters are not considered. All non-uppercase and lowercase letters are considered as only used for segmentation.

Input

The first act is an integer T, indicating the number of data groups.

Each group of data ends with an exclusive row ending with a period.

Output

For each group of test data:

First, an integer n indicates the total number of words in the document;

The next n rows show the words (all in uppercase letters) and the frequency of occurrence in the output articles in alphabetical order.

Sample Input
2
Hello world!
.
ABC-CDE aa1bb2cc3 AAS '(TEST )...
.
Sample output
2
Hello 1
World 1
7
Aa 1
AAS 1
ABC 2
BB 1
CC 1
CDE 1
Test 1

This question is simple statistics and then sorted, but pay attention to the following points:

First, each group of data does not contain only one row, but each row does not contain more than 1000 characters. Therefore, one row is read until the end of reading a row is '.'
Second, when the last character in a row is a letter, you did not process the last word. For example, this line is "ABC. ABC ", the result should be ABC 2, but yourProgramABC 1 will be output, because you didn't process the last word ABC, because it is because you only process the previous word when it is not a letter, but if it is a letter at the end, it will be wrong.

# Include <stdio. h> # include <string. h> int main () {int T, number; int I, j; int K, L; char a [1000] [1001]; int B [1000]; char temp2 [2, 1001]; char temp [1001]; int temp3; int length; char en [3]; scanf ("% d", & number); getchar (); for (t = 1; t <= number; t ++) {k = 0; L = 0; memset (A, '\ 0', sizeof ()); memset (B, 0, sizeof (B); While (true) {gets (temp); If (temp [0] = '. '& strlen (temp) = 1) {break;} length = strlen (temp); for (I = 0; I <length; I ++) {If (temp [I]> = 'A' & temp [I] <= 'Z') {temp2 [L ++] = temp [I];} else if (temp [I]> = 'A' & temp [I] <= 'Z') {temp2 [L ++] = temp [I]-32 ;} else {temp2 [l] = '\ 0'; If (L = 0) continue; For (j = 0; j <K; j ++) {If (strcmp (A [J], temp2) = 0) {B [J] ++; break ;}} if (j = K) {strcpy (A [J], temp2); B [J] ++; k ++;} l = 0 ;}} temp2 [l] = '\ 0 '; if (L = 0) continue; For (j = 0; j <K; j ++) {If (strcmp (A [J], temp2) = 0) {B [J] ++; break ;}} if (j = k) {strcpy (A [J], temp2); B [J] ++; k ++;} l = 0 ;}for (I = 0; I <K; I ++) for (j = I + 1; j <K; j ++) {If (strcmp (A [I], a [J])> 0) {strcpy (temp2, a [J]); temp3 = B [J]; strcpy (A [J], a [I]); B [J] = B [I]; strcpy (A [I], temp2 ); B [I] = temp3 ;}} printf ("% d \ n", k); for (I = 0; I <K; I ++) {printf ("% S % d \ n", a [I], B [I]) ;}} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.