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)
上一篇 2022年1月21日 下午3:00
下一篇 2022年1月21日 下午3:00


相关推荐

  • nfv网络功能虚拟化[通俗易懂]

    nfv网络功能虚拟化[通俗易懂]标题作者及单位文件名日期概述数据度量OnOrchestratingVirtualNetworkFunctionsinNFVMd.FaizulBari,ShihaburRahmanChowdhury,ReazAhmed,andRaoufBoutabaDavidR.CheritonSchoolofComputerScienc…

    2025年9月5日
    7
  • import win32api 找不到指定程序_win32api python

    import win32api 找不到指定程序_win32api python环境描述:使用环境是win7+Python3.4,32位,下载地址:https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/问题1:终端输入importwin32api后,总是报错,错误如下:问题1解决:使用的python-3.4是32位的,win7系统是64位的,在下载pywin32时…

    2022年10月10日
    4
  • cad 打开硬件加速卡_CAD:“你的图纸缺少shx字体!”“不存在的!”

    cad 打开硬件加速卡_CAD:“你的图纸缺少shx字体!”“不存在的!”原标题 CAD 你的图纸缺少 shx 字体 不存在的 点击文末 在看 赞 我们将第一时间出现在你面前每天 8 15 设计气象台准时为你带来最新黑科技干货知识文末附 CAD 万能字体库浓缩版缺少一个或多个 SHX 文件你是不是经常有这样的经历 每每打开 CAD 图纸 总是弹出缺少 SHX 文件的窗口 心里呐喊 WHAT 连忙百度 但又似懂非懂 有时会选择忽略 SHX 并打开 发现图纸上的文字消失了 有时

    2026年3月16日
    2
  • mysql explain ref const_MySQL EXPLAIN 详解「建议收藏」

    mysql explain ref const_MySQL EXPLAIN 详解「建议收藏」一.介绍EXPLAIN命令用于SQL语句的查询执行计划。这条命令的输出结果能够让我们了解MySQL优化器是如何执行SQL语句的。这条命令并没有提供任何调整建议,但它能够提供重要的信息帮助你做出调优决策。先解析一条sql语句,你可以看出现什么内容EXPLAINSELECT*FROMperson,deptWHEREperson.dept_id=dept.didandper…

    2022年10月18日
    5
  • PhpSpreadsheet 学习和使用

    PhpSpreadsheet 学习和使用1、安装composerrequirephpoffice/phpspreadsheet2、usePhpOffice\PhpSpreadsheet\Spreadsheet;usePhpOffice\PhpSpreadsheet\Writer\Xlsx;usePhpOffice\PhpSpreadsheet\Style\Alignment;usePhpOffice\Ph…

    2025年12月12日
    1
  • word2vec 中的数学原理详解(一)目录和前言

    word2vec 中的数学原理详解(一)目录和前言word2vec是Google于2013年开源推出的一个用于获取wordvector的工具包,它简单、高效,因此引起了很多人的关注。由于word2vec的作者TomasMikolov在两篇相关的论文[3,4]中并没有谈及太多算法细节,因而在一定程度上增加了这个工具包的神秘感。一些按捺不住的人于是选择了通过解剖源代码的方式来一窥究竟,出于好奇,我也成为了他们中的一员。读完代码后,觉得收获颇多,整理成文,给有需要的朋友参考。

    2022年5月16日
    45

发表回复

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

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