2023: Statistic map用法

2023: Statistic


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
2s10240K584146Standard

This is my personal contest. Its purpose is to celebrate L.X.X's Birthday. Though L.X. and I have long distance to see each other, you know, she is in Chengdu, I can feel her and always think about her. I hope she will be happy everyday. May 13th is her birthday, happy birthday :)
It is not an easy job to think out some questions, write the test data and source codes. My English is Poor, so there may be some mistakes in the problem description. If you meet the mistakes, please access to http://bbs.jlu.edu.cn Algorithm Board, this is the formal place for you to report the bugs.
I cannot finish this job all by myself without other people's help, they are: Siyee, evil, sea, S—, Leon, zerray. Thanks for their help.
At last, enjoy this contest:)

Input

For this problem, you have to write a program to count the number of the words appeared in the input file. One word consists of 26 lower case letters. So you should convert the upper case letters into lower cases. Words are separated by other symbols. E.G. Sentence "L.X.X" has two different words: l, x. Your program should proceed to the end of the file.

Output

Output all the words appear in the article in the dictionary order, one word per line. For each line, you should output the word first, then a space, and the number of times of this word appeared in the article comes after the space.

Sample Input

Loves X.X

Sample Output

loves 1
x 2

 

Problem Source: billjeff

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<cctype>
using namespace std;
int main()
{
   // freopen("in.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    string str;char ch;
    while(scanf("%c",&ch)==1)  str+=tolower(ch);
    map<string ,int  > q;
    for(int i=0;i<str.size();)
    {
        if(isalpha(str[i]))
        {
            string temp;
            while(isalpha(str[i]))
            {
                temp+=str[i];
                i++;
            }
            q[temp]++;
        }
        else i++;
    }
    map<string,int>::iterator it;
    for(it=q.begin();it!=q.end();it++)
    {
        cout<<it->first<<" "<<it->second<<endl;
    }
    return 0;
}             
               
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值