记录编号 122322 评测结果 AAAAAETETT
题目名称 单词默写 最终得分 50
用户昵称 GravatarHouJikan 是否通过 未通过
代码语言 C++ 运行时间 4.875 s
提交时间 2014-09-23 10:12:52 内存使用 25.98 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <iterator>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <deque>
#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=0x7ffffff;
using namespace std;
//================struct declaration======================
struct node
{
  char ch;
  bool end;
  int freq;
  node *next[30];
  node ()
  {
    this->end=false;
    this->freq=0;
    memset(next,0,sizeof(next)); 
  }
};
//================var declaration=-========================
const int MAXN=500;
int n,m,freq,top=0,cnt;
char word[10010];
node *p,*root;
//================function declaration====================
void dfs(node *x);
//================main code===============================
int main()
{
  string ProgrammeName="engzam";
  string FloderName="COGS";
  freopen((ProgrammeName+".in").c_str(),"r",stdin);
  freopen((ProgrammeName+".out").c_str(),"w",stdout);
#ifdef DEBUG
  clock_t Start_Time=clock();
  system(("copy C:\\Users\\abc\\Desktop\\HouJikan\\"+FloderName+"\\standard.cpp C:\\Users\\abc\\Desktop\\HouJikan\\"+FloderName+"\\submit.txt").c_str());
#endif 
  scanf("%d%d",&n,&m);
  root=new(node);
  For(i,1,n)
  {
    int len;
    cin.ignore(10,10);
    scanf("%s %d",word,&freq);
    p=root;len=strlen(word)-1;
    For(j,0,len)
    {
      if (p->next[word[j]-'a']==NULL)
        p->next[word[j]-'a']=new(node);
      p=p->next[word[j]-'a'];
      p->ch=word[j];
    }
    p->end=true;
    p->freq=freq;
  }
  For(i,1,m)
  {
    LOOP__:
           if (i>m) break;
    cin.ignore(10,10);
    scanf("%s%d",word,&freq);
    p=root;int len=strlen(word)-1;
    For(j,0,len)
      if (p->next[word[j]-'a']==NULL)
      {
        printf("0\n");
        i++;
        goto LOOP__;
      }
      else
        p=p->next[word[j]-'a'];
    cnt=0;
    dfs(p);
    printf("%d\n",cnt);
  }
#ifdef DEBUG
  clock_t End_Time=clock();
  printf("\n\nTime Used :%.6lf Ms\n",double(Start_Time-End_Time)/(-CLOCKS_PER_SEC));
#endif
  return 0;
}
//================function code===========================
void dfs(node *x)
{
  if (x->end&&x->freq>=freq)
    cnt++;
  For(i,0,'z'-'a')
    if (x->next[i]!=NULL)
      dfs(x->next[i]);
  return;
}