2023: Statistic
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 2s | 10240K | 584 | 146 | Standard |
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;
}