小记:1A, 笑炸我,9016MS,
我在杭电的web diy 提交GNU C++也是9016MS
思路:我之前也不晓得map<string, int> 它是怎么按string排序的, 就先试试看,如果是按字母序排那就好了
读取一行数据使用的是getline(cin, str)
然后map[str] ++;记录个数
另外加一个变量cnt,记录总个数
读取完所有数据后,从map的第一个元素开始一个一个的来输出,输出的结果确实是按字母序
但是也担心会TLE,不过不管先提交试试,不行再改
谁知道9016MS 过了、、、、
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-8
const int MAX_ = 101;
const int N = 100010;
const int INF = 0x7fffffff;
string s;
map<string, int> m;
int main() {
、、freopen("f:\\in.txt", "r", stdin);
int n, T, k, p, cnt = 0;
m.clear();
while(getline(cin, s)){
cnt++;
m[s] ++;
}
for(map<string, int>::iterator it = m.begin(); it != m.end(); ++it){
s = it->first;
k = it->second;
cout<<s;
printf(" %.4f\n", k*100.0/cnt);
}
return 0;
}