# Game FZU - 2275（KMP）

Alice and Bob is playing a game.

Each of them has a number. Alice’s number is A, and Bob’s number is B.

Each turn, one player can do one of the following actions on his own number:

1. Flip: Flip the number. Suppose X = 123456 and after flip, X = 654321

2. Divide. X = X/10. Attention all the numbers are integer. For example X=123456 , after this action X become 12345（but not 12345.6）. 0/0=0.

Alice and Bob moves in turn, Alice moves first. Alice can only modify A, Bob can only modify B. If A=B after any player’s action, then Alice win. Otherwise the game keep going on!

Alice wants to win the game, but Bob will try his best to stop Alice.

Suppose Alice and Bob are clever enough, now Alice wants to know whether she can win the game in limited step or the game will never end.

Input

First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

For each test case: Two number A and B. 0<=A,B<=10^100000.

Output

For each test case, if Alice can win the game, output “Alice”. Otherwise output “Bob”.

Sample Input
4
11111 1
1 11111
12345 54321
123 123

Sample Output
Alice
Bob
Alice
Alice

Hint

For the third sample, Alice flip his number and win the game.

For the last sample, A=B, so Alice win the game immediately even nobody take a move.

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
void kmp_pre(char x[],int m,int next[])
{
int i,j;
j=next[0]=-1;
i=0;
while(i<m)
{
while(-1!=j && x[i]!=x[j])
j=next[j];
next[++i]=++j;
}
}
int Next[10010];
int kmp_count(char x[],int m,char y[],int n)
{//x是模式串，y是主串
int i,j;
int ans=0;
kmp_pre(x,m,Next);
i=j=0;
while(i<n)
{
while(-1!=j&&y[i]!=x[j])
j=Next[j];
i++;j++;
if(j>=m)
{
ans++;
j=Next[j];
}
}
return ans;
}
int main()
{
int T,n,m;
cin>>T;
while(T--){
char x[100010],y[1000050];
scanf("%s",x);
scanf("%s",y);
n=strlen(x);
m=strlen(y);
if(m==1&&y[0]=='0'){
printf("Alice\n");
}else if(n<m){
printf("Bob\n");
}else{
if(kmp_count(y,m,x,n)){
printf("Alice\n");
continue;
}
reverse(y,y+m);
if(kmp_count(y,m,x,n)){
printf("Alice\n");
continue;
}
printf("Bob\n");
}
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120