前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)「建议收藏」

POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)「建议收藏」

作者头像
全栈程序员站长
发布2022-07-07 18:45:41
1580
发布2022-07-07 18:45:41
举报

大家好,又见面了,我是全栈君。

题目链接:

PKU:http://poj.org/problem?id=3340

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410

Description

A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and every non-question mark character in X is equal to the character in the same position in W (it means that you can replace a question mark with any digit). For example, 365198 matches the wild number 36?1?

8, but 360199, 361028, or 36128 does not. Write a program that reads a wild number W and a number X from input, both of length n, and determines the number of n-digit numbers that match W and are greater than X.

Input

There are multiple test cases in the input. Each test case consists of two lines of the same length. The first line contains a wild number W, and the second line contains an integer number X. The length of input lines is between 1 and 10 characters. The last line of input contains a single character #.

Output

For each test case, write a single line containing the number of n-digit numbers matching W and greater than X (n is the length of W and X).

Sample Input

代码语言:javascript
复制
36?1?82364288?3910?5#

Sample Output

代码语言:javascript
复制
100
0
4

Source

Tehran 2006

题意:

给出两个数字字符串,串一中有’?’,问在‘?’位置填数字共同拥有多少中填法,保证串一大于串二!

代码例如以下:

代码语言:javascript
复制
#include <cstdio>
#include <cstring>
#include <cmath>
const int maxn = 17;
typedef __int64 LL;
int cont;
LL ans;
char s1[maxn];
char s2[maxn];
LL POW(LL n, LL k)
{
    LL s = 1;
    for(LL i = 0; i < k; i++)
    {
        s*=n;
    }
    return s;
}
void solve(int len, int k)
{
    for(int i = 0; i < len; i++)
    {
        if(s1[i] == '?')        {            ans+=(9-(s2[i]-'0'))*POW(10,--cont);        }        else if(s1[i] < s2[i])            return ;        else if(s1[i] > s2[i])        {            ans+=POW(10,cont);            return ;        }    }}int main(){    while(~scanf("%s",s1))    {        ans = 0;        cont = 0;        if(s1[0] == '#')            break;        scanf("%s",s2);        int len = strlen(s1);        for(int i = 0; i < len; i++)        {            if(s1[i] == '?')                cont++;        }        solve(len,0);        printf("%I64d\n",ans);    }    return 0;}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116429.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档