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


相关推荐

  • ie浏览器最大化快捷键(电脑退出最大化快捷键)

    最小化的快捷键 WIN+M 按“Windows键+M”键可以最小化所有被打开的窗口,相当于“显示桌面”功能。·窗口最大化快捷键 Shift+WIND+MWindows键+CTRL+M功能是:重新将恢复上一项操作前窗口的大小和位置·在最大化和最小化之间切换的快捷键:WIN+D· 最大化ALT+空格+X  最小化ALT+空格+N其它有关WINDOWS键的快捷

    2022年4月12日
    686
  • 使用playbook安装nginx和mysql

    使用playbook安装nginx和mysql

    2021年5月31日
    131
  • asp.net中的Gridview控件添加序号列

    asp.net中的Gridview控件添加序号列asp.net中的Gridview控件添加序号列

    2022年4月24日
    64
  • windowspythonpygame安装_pygame安装(windows pycharm)[通俗易懂]

    windowspythonpygame安装_pygame安装(windows pycharm)[通俗易懂]一、安装流程1.查看python版本2.检查是否安装pip3.下载pygame安装文件选择合适的版本(我选择的是python3.7windows64bit):4.使用pip安装pygame将下载好的whl文件移动到python安装目录的\Lib\site-packages下(我的路径是D:\ProgramFiles\Python\Python37\Lib\site-packages),然后…

    2022年5月23日
    46
  • Java审计之文件操作漏洞

    Java审计之文件操作漏洞篇0x00前言本篇内容打算把Java审计中会遇到的一些文件操作的漏洞,都给叙述一遍。比如一些任意文件上传,文件下载,文件读取,文件删除,这些操作文件的漏洞。0x01

    2021年12月12日
    35
  • 项目管理-5大过程组-10大知识领域-47过程

    项目管理五大过程组:1、启动过程组:获得授权,定义一个新项目或现有项目的一个新阶段,正式开始该项目或阶段的一组过程。2、规划过程组:明确项目范围,优化目标,为实现目标而制定行动方案的一组过程。3、执行过程组:完成项目管理计划中确定的工作以实现项目目标的一组过程。4、监控过程组:跟踪、审查和调整项目进展与绩效,识别必要的计划变更并启动相应变更的一组过程。5、收尾过程组:为完结所有过程组的…

    2022年4月13日
    48

发表回复

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

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