标签:ash call code int continue eth guess 猜数字 har
char * getHint(char * secret, char * guess){ int shash[10]={0}; int ghash[1000]={0}; int i, len=strlen(secret), A=0, B=0, l=0; char* s=(char*)calloc(10,sizeof(char)); for (i=0; i<len; i++) { shash[secret[i]-‘0‘]++; if(secret[i]==guess[i]){ shash[secret[i]-‘0‘]--; ghash[i]++; A++; } } for (i=0; i<len; i++) { if(ghash[i]) continue; if(shash[guess[i]-‘0‘]>0){ shash[guess[i]-‘0‘]--; B++; } } sprintf(s,"%dA%dB",A,B); return s; }
标签:ash call code int continue eth guess 猜数字 har
原文地址:https://www.cnblogs.com/ganxiang/p/14218605.html