POJ2418

来源:互联网 发布:程序员该怎么建立博客 编辑:程序博客网 时间:2024/05/01 17:50

 摘要:水,排序

 

#include <iostream>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;

const int size = 1000000;
string input[size];
int main()
{
    char tree[50];
    int index = 0;
        while(fgets(tree, 45, stdin)){
        //string temp = tree;
        //temp = temp.substr(0, temp.length()-1);   
            input[index++] = tree;
        }
   
    sort(input, input+index);
   
    double total = index;   
    int pre_pos = 0;   
    for(int i=0; i<index; i++){
        if(input[i] != input[pre_pos]){
            printf("%s %.4f/n", input[pre_pos].substr(0, input[pre_pos].length()-1).c_str(), 100 * (i-pre_pos)/total);
            pre_pos = i;
        }
    }
       
    printf("%s %.4f/n", input[pre_pos].substr(0, input[pre_pos].length()-1).c_str(), 100 * (index-pre_pos)/total);

    return 0;
}

原创粉丝点击