猜数字的问题? 求助
题目描述:猜数字游戏大家玩过没?经典的规则是给出一个四位数,然后你去猜。
如那个数是1357,你猜1234的话,就给出1A1B,这是什么意思呢?
nA表示有n个数的位置猜对了,nB表示有n个数猜对了,但位置不对,
如果你再猜2351当然给出2A1B了,如果你猜2468,那就是0A0B了。
现在,把四位数扩展到n位,由数字扩展到字符,输入两个字符串,你
判断出猜对位置的和猜对了但位置不对的。如abcdefg和aceg123,结
果就是1A3B
输入:
多组测试数据,每组占一行,每行有两个字符串,串长小于10000,用空格分隔开
输出:
输出这两个字符串比较的结果
样例输入:
1357 1234
abcdefg aceg123
AaAa AAaa
121212 2121212211
Qq qqGame
样例输出:
1A1B
1A3B
2A2B
0A6B
1A0B
我的代码:
程序代码:
#include<iostream>
#include<cstring>
using namespace std;
const int Max=10000;
int main()
{
char A[Max],B[Max],F[Max];
int i=0,j=0,Alen=0,Blen=0,len=0;
int Ncount=0,Pcount=0;
cin>>A>>B;
Alen=strlen(A);
Blen=strlen(B);
len=Alen>Blen?Alen:Blen;
for(i=0;i<len;i++) //找出相同的
{
if(A[i]==B[i]) Ncount++;
}
for(i=0;i<Alen;i++) //flag
F[i]=0;
for(j=0;j<Blen;j++) //找出B中与A相同字符的个数,
for(i=0;i<Alen;i++)
{
if( (B[j]==A[i]) && F[i]!=1 )
{
Pcount++;
F[i]=1;
break;
}
} //Pcount-Ncount则为猜对了,但位置不对的
cout<<Ncount<<"A"<<Pcount-Ncount<<"B"<<endl;
return 0;
}
G++: Compile OK
Test 1: Wrong Answer
--------------------------------
Problem ID 43
Test Result Wrong Answer
Total Time NULL
Total Memory 168 Kb / 65536 Kb
Code Length 566 Bytes
题目上的几个例子都是对的呀。。。
不知道什么地方错了。。。
哪位帮忙看看?~~~谢谢..
附个测试数据。顺便问下怎么用。。没用过






