当前位置: 代码迷 >> 综合 >> 2015‘12杭电校赛1008 Study Words(map,vector瞎搞)
  详细解决方案

2015‘12杭电校赛1008 Study Words(map,vector瞎搞)

热度:40   发布时间:2023-09-14 02:32:36.0

题解:

有中文输入吓了一跳,不过强行各种STL开搞!

代码

#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <bitset>
#define MAX 100000
#define LL long long
using namespace std;
int cas=1,T,n;
char word[110];
int main()
{// freopen("in","r",stdin);scanf("%d",&T);while(T--){scanf("%*s");set<string>old;map<string,int>news;old.clear();news.clear();while(scanf("%s",word)&&word[0]!='<'){for(int i=0;word[i];i++) word[i]=tolower(word[i]);
// puts(word);old.insert(word);}scanf("%*s");char c,flag=0,i=0;while(c=getchar()){if(c=='<') break;if(isalpha(c)){c=tolower(c);word[i++]=c;flag=1;}else if(flag){word[i]=0;
// puts(word);i=flag=0;if(old.count(word)) continue;news[word]++;}}scanf("%*s");for(int i=0;i<10&&!news.empty();i++){string maxs;int maxt=0;for(map<string,int>::iterator it=news.begin();it!=news.end();it++){if(maxt<it->second||maxt==it->second&&maxs > it->first){maxt=it->second;maxs=it->first;}}cout<<maxs<<endl;news.erase(maxs);}puts("");}//printf("time=%.3lf\n",(double)clock()/CLOCKS_PER_SEC);return 0;
}

题目

Study Words

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 267 Accepted Submission(s): 97

Problem Description

Learning English is not easy, vocabulary troubles me a lot.
One day an idea came up to me: I download an article every day, choose the 10 most popular new words to study.
A word’s popularity is calculated by the number of its occurrences.
Sometimes two or more words have the same occurrences, and then the word with a smaller lexicographic has a higher popularity.

Input

T in the first line is case number.
Each case has two parts.
< oldwords >

< /oldwords >
< article >

< /article >
Between and are some old words (no more than 10000) I have already learned, that is, I don’t need to learn them any more.
Words between and contain letters (‘a’~’z’,’A’~’Z’) only, separated by blank characters (’ ‘,’\n’ or ‘\t’).
Between

and
  相关解决方案