⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1899.cpp

📁 第一次这么大规模地使用stl,果然比纯c慢很多
💻 CPP
字号:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

char a[10001][31];
map<string,int> table;

int Comp(const void* a,const void* b)
{
    char* aa=(char*)a;
    char* bb=(char*)b;
    
    return strcmp(aa,bb);
}

int main()
{
    int i,j,cnt,char_num,count,cas=1;
    char s[31];

    //freopen("in.txt","r",stdin);
    cnt=0;
    count=0;
    while(gets(s))
    {
        count++;
        if(table.count(s)==0)
        {
            strcpy(a[cnt++],s);
            table.insert(make_pair(s,1));
        }
        else
            ++table[s];
        while(gets(s)&&strlen(s)!=0)
        {
            count++;
            if(table.count(s)==0)
            {
                 strcpy(a[cnt++],s);
                 table.insert(make_pair(s,1));
            }
            else
                ++table[s];            
        }
        qsort(a,cnt,sizeof(a[0]),Comp);
        if(cas!=1) putchar('\n');
        for(i=0;i<cnt;i++)
            printf("%s %.4lf\n",a[i],table[a[i]]*100.0/count);
        cnt=0;;
        count=0;
        cas++;
        table.clear();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -