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

POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)

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

题目链接:

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

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

Description

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

36?

1?

82364288?3910?5#

Sample Output

100
0
4

Source

题意:

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


代码例如以下:

#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.net/116429.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • dota2已连接协调服务器,正在登陆中的解决办法「建议收藏」

    dota2已连接协调服务器,正在登陆中的解决办法「建议收藏」这两天,家里有亲戚过世,暗恋的小姑娘跟别人出去玩了,心情不好,打开dota2,连了好几次都没连上,按网上的说法清除缓存,重启电脑都试过了,不行,后来发现,我是手机开的热点,这里信号不好,换一个信号好的卡就行了,很多关于网络的问题其实都和网速有关,因为网速不合格和断网基本上是同一个问题,所以一般会引起混淆。…

    2022年5月17日
    141
  • bootstrap table editable 文档_bootstrap复选框样式

    bootstrap table editable 文档_bootstrap复选框样式问题描述:采用bootstrap中的table进行页面布局,然后通过ajax请求数据源,然后动态添加表格内容。添加时,采用的自己拼接字符串,然后追加到表格中。结果发现bootstrap的表格样式没有生效。页面代码:消费类别描述消费数量消费时间JS代码:$.ajax({ty

    2022年9月20日
    3
  • Prism初研究之Bootstrapper

    Prism初研究之BootstrapperPrism初研究之初始化应用Prism初研究之初始化应用BootstrapperDIShell关键抉择核心步骤创建Bootstrapper实现CreateShell方法实现InitializeShell方法创建并配置ModuleCatalog创建并配置Container核心服务(与应用无关)与应用相关的服务(StockTraderRI)在UnityBootstrapper中创建并配置…

    2022年7月20日
    18
  • struts2和struts1认识

    struts2和struts1认识

    2022年1月6日
    40
  • vbs表白代码+整人代码,抖音vbscript表白代码

    vbs表白代码+整人代码,抖音vbscript表白代码步骤一:在电脑上新建一个txt文件步骤二:将以下代码复制过去(中文可以改)consttitle=“爱情测试”constyourname=“嫦娥”constquestion=“你最喜欢的人是谁?请在下面的方框中输入他(她)的名字。”constinfo=“你在说谎!不要逃避,实话实说。”constscend=“你说出了你的心扉,那就向他(她)表白吧。”di…

    2022年6月8日
    46
  • pycharm远程调试python_pycharm调试教程

    pycharm远程调试python_pycharm调试教程pycharm远程开发与调试0.为pycharm添加远程服务器配置如果你已经为该服务器配置过远程服务器,可忽略此步骤。打开pycharm,tools-&amp;amp;amp;amp;gt;Deployment-&amp;amp;amp;amp;gt;Configuration,在左边栏点“+“号添加远程服务器。右边配置如下图,只需要配置connection,注意”Visibleonlyforthisproject”的勾去掉!…

    2022年8月29日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号