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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • goland 2021.2.3 服务器激活(在线激活)

    goland 2021.2.3 服务器激活(在线激活),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月14日
    365
  • TCN代码随记(如何记代码)

    标题np.arange()np.arange()函数返回一个有终点和起点的固定步长的排列,如[1,2,3,4,5],起点是1,终点是6,步长为1。参数个数情况:np.arange()函数分为一个参数,两个参数,三个参数三种情况1)一个参数时,参数值为终点,起点取默认值0,步长取默认值1。2)两个参数时,第一个参数为起点,第二个参数为终点,步长取默认值1。3)三个参数时,第一个参数为起点,第二个参数为终点,第三个参数为步长。其中步长支持小数np.random.shufflenp.random

    2022年4月11日
    75
  • Java 实现异步调用

    Java 实现异步调用首先我遇到的问题是接口调用时需要更新缓存而更新缓存又是个说快不快的过程所以打算做异步调用返回我所需要的结果即可,至于缓存什么时候更新完就不是我所需要关注的了废话不多说上代码publicclassMyExecutor{  privateExecutorServiceexecutor=Executors.newCachedThreadPool();  publi…

    2022年7月27日
    10
  • (翻译)什么是Java的永久代(PermGen)内存泄漏

    (翻译)什么是Java的永久代(PermGen)内存泄漏转自:http://www.codelast.com/本文是我对这篇文章的翻译:WhatisaPermGenleak? 为了便于阅读,我将原文附于此处,翻译穿插在其中。此外,为了防止原链接在未来某一天失效后,文中的图片再也看不到的问题,我将原文中的图片也保存到了本站的服务器上,我不知道原作者是否允许这样做,但我翻译本文仅在于传播知识的目的,在此向原作者表示深深的感谢:感谢你

    2022年6月29日
    33
  • 如何实现自定义类加载器_开发者不可以自定义类加载器

    如何实现自定义类加载器_开发者不可以自定义类加载器为什么要有类加载器类加载的过程初识类加载器类加载机制自定义类加载器为什么要有类加载器我们知道java中所有的二进制文件,最后都是要放在jvm中解释运行的。纯粹的二进制文件,其实并没有什么卵用。jvm在第一次使用或者预加载时,都要将某个类的二进制文件加载进去,这时候不可避免的需要用到一个加载的触手,就是这个类加载器啦。类的加载过程简单来说,一般可分为加载、连接、初始化三个过程。加载,顾名思义

    2022年9月5日
    2
  • 【FinE】在险价值(VaR)计算「建议收藏」

    【FinE】在险价值(VaR)计算「建议收藏」VaR值计算

    2022年7月21日
    22

发表回复

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

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