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


相关推荐

  • AOSP开源协议_open sap

    AOSP开源协议_open sapOLAP(OnlineAnalyticalProcessing)是指在线联机分析,基于数据查询计算并实时获得返回结果。日常业务中的报表、数据查询、多维分析等一切需要即时返回结果的数据查询任务都属于OLAP的范畴。对应的,行业内也有相应产品来满足这类需求,那就是OLAPServer。当前主流OLAPServer几乎都是基于RDB或封装成RDB的大数据平台,有点类似早期的ROLAP(这个词已经很少被提及了),其中一个关键的特征是使用SQL作为查询语言。RDB和SQL的特性会给OLAPServer带来诸

    2025年8月10日
    8
  • 最近游戏更新 未整理 无图片 续传_续薪火浅浅烂

    最近游戏更新 未整理 无图片 续传_续薪火浅浅烂模拟人生之超级明星(TheSims:Superstar)三项属性修改器http://patch.ali213.net/download.asp?id=2872黑客帝国(EntertheMatrix)v1.51升级档五项属性修改器http://patch.ali213.net/download.asp?id=2868黑客帝国(EntertheMatrix)v1.52升级档激活成功教程版

    2022年9月21日
    2
  • android移动点餐系统内容和要求,基于Android云计算的移动点餐系统

    android移动点餐系统内容和要求,基于Android云计算的移动点餐系统摘要:系统发挥Android富有创造力和想象力的云应用开发,实现一套Android客户端软件和完善的后台服务功能来完成点餐功能。该系统主要包括后台数据库服务器、WEB服务器、无线网络、Android前端等部分。客户端Android系统智能手机具有前端处理与计算能力,而且通过无线网络访问WEB服务器,如果需要数据访问,则访问后台数据库。介绍了系统架构的设计与搭建、技术选型、后台数据库的…

    2022年6月20日
    34
  • arm cortex-a57 cpu_处理器a73和a53

    arm cortex-a57 cpu_处理器a73和a53在如今这个电子产品泛滥的年代,仅仅靠品牌或是外观已经不足以辨别产品的优劣,其内置的处理器自然也就成为了分辨产品是否高端的标准之一。那么我们今天就不妨好好了解一下近几年来电子产品中较为主流的RAM处理器。  在这之前让我们先简单认识一下处理器的架构。所谓处理器架构是CPU厂商给属于同一系列的CPU产品定的一个规范,主要目的是为了区分不同类型CPU的重要标示。目前市面上的CPU指令集分类主要分有…

    2022年8月31日
    16
  • CAP原理通俗理解「建议收藏」

    CAP原理通俗理解「建议收藏」在分布式系统中,有一个基本原则叫做CAP,consistence,一致性,availability,可用性,partitiontolerance分区容错性。 一致性,在这里指的是分布式系统的各个副本的值要保持同步,这里强的是空间上的一致,注意和数据库中ACID中的一致性相区分,那个一致性指的是事务执行前后的逻辑一致性,比如你转1000块给别人,不能你的账户少了1000块,对方的账户却没有多10…

    2022年5月12日
    47
  • 回归问题-Lasso回归[通俗易懂]

    回归问题-Lasso回归[通俗易懂]Lasso(Leastabsoluteshrinkageandselectionoperator)方法是以缩小变量集(降阶)为思想的压缩估计方法。它通过构造一个惩罚函数,可以将变量的系数进行压缩并使某些回归系数变为0,进而达到变量选择的目的。正则化正则化(Regularizaiton)是一种防止过拟合的方法。…

    2022年4月27日
    49

发表回复

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

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