标签:script ace string integer span some 相等 cstring ups
Xiaoqiang wrote a decimal number \(X\), but some of the handwriting has been blurred (we replaced it with ?). Now given another decimal number \(Y\) with the same number of digits, he wants to know how many possibilities make \(X>Y\).
The first line is a positive integer \(t(\leq 100)\), indicating the number of data groups; in each group of data, the first line is a decimal number \(X\) within 16 digits, how many of them ? ; The second line is a decimal number \(Y\) with the same number of digits.
Output the possible number of \(X>Y\).
1
36?1?8
236428
100
#include <cstdio>
#include <cstring>
typedef long long ll;
ll p10[18]={1};
int main(){
freopen("wild.in","r",stdin);
freopen("wild.out","w",stdout);
for (int i=1; i<18; i++)
p10[i]=p10[i-1]*10;
int t;
scanf("%d", &t);
while (t--){
char s[20], v[20];
scanf("%s", s);
scanf("%s", v);
int n=strlen(s), w=0;
for (int i=0; i<n; i++)
if (s[i]==‘?‘) w++;//统计?个数
ll ans=0ll;
for (int i=0; i<n; i++)//分四种情况:
if (s[i]==‘?‘) //1、?
ans+=(‘9‘-v[i])*p10[--w];
else if (s[i]<v[i])//2、<
break;
else if (s[i]>v[i]){//3、>
ans+=p10[w];
break;
} //4、相等,继续
printf("%lld\n", ans);
}
return 0;
}
标签:script ace string integer span some 相等 cstring ups
原文地址:https://www.cnblogs.com/jiupinzhimaguan/p/13832986.html