zoukankan      html  css  js  c++  java
  • poj2418 map 快排水过

    /*计算每个单词的百分比按字典序输出*/


    #include <cstdio>
    #include<cstdlib>
    #include <cstring>
    #include <cctype>
    #include <string>
    #include <map>
    #include <algorithm>
    #include <iostream>

    using namespace std;

    struct tt
    {
        char w[40];
        bool operator < (const tt a)const
        {
            int t = strcmp(w,a.w);
            if(t < 0)
                return true;
            return false;
        }
    };

    int n;
    map<string,int>sad;
    map<string,bool>sadd;
    tt tre[10100];

    int main()
    {
        //freopen("input.in","r",stdin);
        char str[40];
        int count = 0;
        memset(tre,0,sizeof(tre));
        n = 0;
        while(fgets(str,35,stdin) != NULL)
        {
            if(str[0] == ' ')
                break;
            int len = strlen(str);
            str[len-1] = '';
            count++;
            if(!sadd[str])
            {
                strcpy(tre[n++].w,str);
                sadd[str] = true;
            }
            sad[str]++;
        }
        sort(tre,tre+n);
        for(int i = 0;i < n;i++)
        {
            double temp = 1.0*sad[tre[i].w] / count *100;
            printf("%s %.4lf ",tre[i].w,temp);
        }
        return 0;
    }

  • 相关阅读:
    新浪微博采用Oauth发送图片和文字
    android proguard也有弱点
    POJ 2376
    POJ 3259
    POJ 2253
    POJ 1062
    POJ 2299
    POJ 2186
    POJ 1860
    POJ 2823
  • 原文地址:https://www.cnblogs.com/hanbinggan/p/4463878.html
Copyright © 2011-2022 走看看