hdu 1219 AC Me

22 篇文章 0 订阅

题意:水题。。。就是求a-z字母出现的次数。注意每个测试事件之间有一个空白行。


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();
			//初始化为零
			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();//这个注意
		}
	}

}

c语言代码:

#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 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.
真的很容易,对吧!来!让我们解决他。

Input
Each 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.
所以没有必要去考虑其他的字母。文章的长度小于等于10万。直接输入到文件末尾。
Note: the problem has multi-cases, and you may use "while(gets(buf)){...}" to process to the end of file.
 注意:问题有多个,你可以用"while(gets(buf)){...}" 语句去处理问题知道文件末尾。

Output
For 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 Input
  
  
hello, this is my first acm contest! work hard for hdu acm.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值