UVa 10008 Whats Cryptanalysis

Code:
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<cctype>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,char> ii;
struct ff
{
    int num;
    char cha;
    ff(int n,char ch) : num(n),cha(ch) {}
    bool operator < (const ff &rhs) const
    {
        if(num>rhs.num) return true;
        if(num==rhs.num)
        {
            if(cha<rhs.cha) return true;
        }
        return false;
    }
};
int main()
{
    int cas;
    string line;
    map<char,int> ma;
    vector<ff> v;
    while(cin>>cas)
    {

        getline(cin,line);
        for(int cc=0; cc<cas; cc++)
        {
            string str;
            getline(cin,str);
            int len=str.length();
            for(int i=0; i<len; i++)
            {
                if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
                {
                    char ch=toupper(str[i]);
                    ma[ch]+=1;
                }
            }
        }
    }
    for(map<char,int>::iterator it=ma.begin(); it!=ma.end(); it++)
    {

        v.push_back(ff(it->second,it->first));
    }
    sort(v.begin(),v.end());
    int lenv=v.size();
    for(int i=0; i<lenv; i++)
    {
        printf("%c %d\n",v[i].cha,v[i].num);
    }
    return 0;

}

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble