Question: Water problem ... is to find the number of times a-Z letter appears. Note There is a blank line between each test event.
Import Java.util.Scanner;
public class Main {public
static void Main (string[] args) {
Scanner sc = new Scanner (system.in);
Int[] Mat = new INT[26];
int temp = 0;
while (Sc.hasnext ()) {
String test = Sc.nextline ();
Initialized to 0 for
(int i = 0; i < mat.length i++) {
mat[i] = 0;
}
for (int i = 0; i < test.length (); i++) {
char ch = test.charat (i);
if (ch<= ' z ' &&ch>= ' a ') {
temp = (int) (ch-' a ');
mat[temp]++
}
}
for (int i = 0; i < mat.length i++) {
System.out.println ((char) (' a ' +i) + ":" +mat[i]);
}
System.out.println ();//This Note}}}
C Language code:
#include <iostream>
#include <string>
using namespace std;
int main () {
string str;
while (Getline (CIN,STR)) {
int a[26];
for (int i=0;i<26;i++) {
a[i] = 0;
}
for (int i=0;i<str.length (); i++) {
if (islower (str[i)) {
a[str[i]-' a ']++;
}
} for (int i=0;i<26;i++) {
Cout<<char (i+ ' a ') << ":" <<a[i]<<endl;
}
cout<<endl;
}
return 0;
}
AC Me Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 13911 accepted Submission (s): 6110
Problem Description Ignatius is doing he homework now. The teacher gives him some articles and asks him to tell you the times, each letter many.
Ignatius Matthews is doing his homework now. His teacher gave him several articles and asked him to find out the number of times each letter appeared in each post.
It ' s really easy, isn ' t it? So come on and AC ME.
It's really easy, isn't it. To. Let's fix him.
Input Each article consists of just one, and all letters are in lowercase. You are just have to count the number of every letter, only one line for each article, and the letters entered are lowercase. Your task is to calculate the number of times each letter appears. So don't pay attention to the other characters. The length of article is at most 100000. Process to the end of file.
So there's no need to think about other letters. The length of the article is less than or equal to 100,000. Enter the end of the file directly.
Note:the problem has multi-cases, and you would use "while" (Gets (BUF)) {...}
Note: There are multiple problems, you can use the "while (gets) {...}" statement to handle the problem to know the end of the file.
Output for each article, and you are have to the tell the many times each letter appears. The output format is like "X:n".
For each article, you have to figure out how many times each letter appears. The format of the input is shown in the following example.
Output a blank line after the test case. More details in sample output.
Each test event is isolated with a blank line.
Sample Input
Hello, this is the My-i-ACM contest! Work hard for HDU ACM.