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

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

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

相关推荐

  • hibernate与mybatisplus_Mybatis框架

    hibernate与mybatisplus_Mybatis框架最近做了一个Hibernate与MyBatis的对比总结,希望大家指出不对之处。第一章     Hibernate与MyBatisHibernate 是当前最流行的O/Rmapping框架,它出身于sf.net,现在已经成为Jboss的一部分。 Mybatis 是另外一种优秀的O/Rmapping框架。目前属于apache的一个子项目。MyBatis 参考资料官网:ht

    2022年9月11日
  • java 正则表达式详细讲解和全面案例,和根据正则筛选需要内容「建议收藏」

    java 正则表达式详细讲解和全面案例,和根据正则筛选需要内容「建议收藏」java 正则表达式详细讲解和全面案例,和根据正则筛选需要内容

    2022年4月23日
  • 1、win10下的python3.5.4安装

    现在越来越多人入坑python了,当然我也不例外。作为一个java程序员的我,在空余时间就慢慢学习python了 。第一件事就是安装Python啦。(主要以Python 3.5.4为例)一、官网下载安装包官网地址:https://www.python.org/downloads/windows/ 都说越新越好嘛,其实我觉得都差不多,但是3.6跟3.5还是有点区别的嘛,所以我…

    2021年11月30日
  • return 0和return 1和return -1的区别「建议收藏」

    return 0和return 1和return -1的区别「建议收藏」1、返回值int类型的函数返回:return语句用来结束循环,或返回一个函数的值。return0:一般用在主函数结束时,按照程序开发的一般惯例,表示成功完成本函数。return-1::表示返回一个代数值,一般用在子函数结尾。按照程序开发的一般惯例,表示该函数失败;以上两个是约定俗成,系统提供的函数绝大部分定义为int类型返回值的都是这样的。返回值是返回给系统用的,给…

    2022年10月21日
  • linux 重启服务器命令[通俗易懂]

    linux 重启服务器命令[通俗易懂]Linux有如下的关机和重启命令:shutdown,reboot,halt,poweroff,那么它们有什么区别呢?shutdown-建议使用的命令shutdown是最常用也是最安全的关机和重启命令,它会在关机之前调用fsck检查磁盘,其中-h和-r是最常用的参数:-h:停止系统服务并关机-r:停止系统服务后重启下面看几个例子:shutdown-h…

    2022年10月18日
  • pycharm安装Translation翻译插件(中文翻译)「建议收藏」

    pycharm安装Translation翻译插件(中文翻译)「建议收藏」打开pytcharm选择文件——设置找到plugins——在输入框搜索translation进行安装即可设置翻译工具的唤醒快捷键位置:快捷键——在输入框输入名称,右击选择啊大大keyboardshortcut自定义就可以了选择翻译的工具如图所示:进入pycharm,按快捷键呼出翻译界面,输入内容,按回车按钮…

    2022年10月27日

发表回复

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

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