图书管理员
Time Limit:10000MS Memory Limit:265536K
Case Time Limit:2000MS
Description
你是一所学校的图书管理员,你的工作有如下几种操作:
A.添加一本书
B.借出一本书
C.查找一本书
你这学期要完成n次操作,非常辛苦,你想编写一个程序来帮助你。
Input
第一行一个整数n,表示操作的次数。
接下来n行,每行由一个大写字母和一个单词构成,大写字母表示操作的种类,单词表示对应的书名
Output
对于每次查询,输出查询的结果,找到输出"yes",没找到输出"no"。
Sample Input
10
A zerow
A alien
A newton
B jack
A nicole
C newton
B nicole
A pugna
C alien
C zerowb
Sample Output
yes
yes
no
Hint
0<=n<=200000
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 20000
int ans[maxn+9], m;
struct node{int num, next[4];}trie[maxn*21];
char dna[21];
int tot=1;
void insert()
{
int i, p=1;
for(i=0; i<m; i++)
{
int t=dna[i];
if(0==trie[p].next[t])
{
tot++;
trie[p].next[t]=tot;
}
p=trie[p].next[t];
}
trie[p].num++;
}
inline void _out(int d)
{
int o[30],top=1;
if(d==0){putchar('0');return ;}
if(d<0) {putchar('-');d=-d;}
while(d)
{
o[top++]=d%10;
d/=10;
}
for(--top;top;--top) putchar('0'+o[top]);
}
int main()
{
int n, i;
scanf("%d%d", &n, &m);
while(n&&m)
{
getchar();
for(int j=0; j<n; j++)
{
//read
for(i=0; i<m; i++)
{
dna[i]=getchar();
switch(dna[i])
{
case 'A':
dna[i]=0;
break;
case 'C':
dna[i]=1;
break;
case 'G':
dna[i]=2;
break;
case 'T':
dna[i]=3;
break;
}
}
getchar();
insert();
}
for(int i=1; i<=tot; i++)
{
if(trie[i].num)
{
ans[trie[i].num-1]++;
}
trie[i].num=0;
for(int j=0; j<4; j++) trie[i].next[j]=0;
}
for(int i=0; i<n; i++)
{
_out(ans[i]);
ans[i]=0;
putchar('\n');
}
tot=1;
scanf("%d%d", &n, &m);
}
return 0;
}
2047

被折叠的 条评论
为什么被折叠?



