Acm hdu 1219 AC me (simple question, but it takes a long time to AC)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1219

Simple question.

Gains:

Use of gets.

AC me

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 5280 accepted submission (s): 2388

Problem descriptionignatius is doing his homework now. The teacher gives him some articles and asks him to tell how many times each letter appears.

It's really easy, isn' t it? So come on and AC me.

 

Inputeach article consists of just one line, and all the letters are in lowercase. you just have to count the number of each letter, so do not pay attention to other characters. the length of article is at most 100000. process to the end of file.

Note: The problem has multi-cases, and you may use "while (gets (BUF) {...}" to process to the end of file.

 

Outputfor each article, you have to tell how many times each letter appears. The output format is like "X: N ".

Output a blank line after each test case. More details in sample output.

 

Sample inputhello, this is my first ACM contest!
Work hard for hdu acm.

 

Sample outputa: 1
B: 0
C: 2
D: 0
E: 2
F: 1
G: 0
H: 2
I: 3
J: 0
K: 0
L: 2
M: 2
N: 1
O: 2
P: 0
Q: 0
R: 1
S: 4
T: 4
U: 0
V: 0
W: 0
X: 0
Y: 1
Z: 0

A: 2
B: 0
C: 1
D: 2
E: 0
F: 1
G: 0
H: 2
I: 0
J: 0
K: 1
L: 0
M: 1
N: 0
O: 2
P: 0
Q: 0
R: 3
S: 0
T: 0
U: 1
V: 0
W: 1
X: 0
Y: 0
Z: 0

 

Authorignatius. L

 

Source Hangzhou University of Electronic Science and Technology's third Program Design Competition

 

Recommendignatius. L
 # Include  <  Stdio. h  >  
# Include < Iostream >
# Include < String . H >
Using Namespace STD;
Int Num [ 26 ];
Char Let [ 27 ] = " Abcdefghijklmnopqrstuvwxyz " ;
Char STR [ 20000 ];
Int Main ()
{
// Freopen ("test. In", "r", stdin );
// Freopen ("test. Out", "W", stdout );
Int I;
While (Gets (STR ))
{
Memset (Num, 0 , Sizeof (Num ));
Int Len = Strlen (STR );
// If (LEN = 0) break;
For ( Int I = 0 ; I < Len; I ++ )
{
If (STR [I] > = ' A ' && STR [I] <= ' Z ' )
{
Int T = STR [I] - ' A ' ;
Num [T] ++ ;
}
}
For ( Int I = 0 ; I < 26 ; I ++ )
Printf ( " % C: % d \ n " , Let [I], num [I]);
Printf ( " \ N " );
}
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.