记录编号 119170 评测结果 AAAAAAAAAA
题目名称 [NOIP吧] 这也叫破译? 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.734 s
提交时间 2014-09-11 16:00:52 内存使用 0.70 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=0x7fffffff;
//==============struct declaration==============
struct words
{
  string spell;
  int weight;
  bool operator<(const words &rhs) const
  {
    if (weight!=rhs.weight)
      return weight>rhs.weight;
    if (spell.length()!=rhs.spell.length())
      return spell.length()>rhs.spell.length();
    return spell>rhs.spell;
  }
}word[50000];
//==============var declaration=================
int w[30]={4,2,5,6,1,4,5,6,7,2,3,4,8,9,3,1,2,6,8,9,2,6,3,2,5,7};
int n,m;
//==============function declaration============

//==============main code=======================
int main()
{  
  string FileName="crack";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif 
  scanf("%d%d",&n,&m);   
  For(i,1,n)
  {
    cin>>word[i].spell;
    int len=word[i].spell.length();
    word[i].weight=0;
    For(j,0,len-1)
      word[i].weight+=w[word[i].spell[j]-'a'];
  } 
  nth_element(word+1,word+1+m,word+n+1);
  sort(word+1,word+1+m);
  For(i,1,m)
    cout<<word[i].spell<<" "<<word[i].weight<<endl;
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif    
  return 0;
}
//================fuction code====================