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


相关推荐

  • 桶排序算法c语言_哪种排序算法最快

    桶排序算法c语言_哪种排序算法最快在前几回我们已经对冒泡排序、直接插入排序、希尔排序、选择排序、快速排序、归并排序、堆排序、计数排序做了说明分析(具体详情可在公众号历史消息中查看)。本回,将对桶排序进行相关说明分析。一、排序算法系列目录说明冒泡排序(BubbleSort)插入排序(InsertionSort)希尔排序(ShellSort)选择排序(SelectionSort)快速排序(Quick…

    2025年8月9日
    4
  • 解决:如何写一个shell脚本(脚本名称:xsync,也称:xsync命令):实现多个电脑或者虚拟机之间的文件同步?

    解决:如何写一个shell脚本(脚本名称:xsync,也称:xsync命令):实现多个电脑或者虚拟机之间的文件同步?写一个shell脚本(脚本名称:xsync,又称xsync命令):实现多个电脑或者虚拟机之间的文件同步?一·xsync命令与rsync命令之间关系介绍:(1)xsync命令来源于一个xsync的脚本,这个脚本不是Linux系统自带的,是程序员自己写的。(2)xsync脚本的底层,实质是调用Linux系统自带的rsync命令,来实现多个电脑之间的快速文件同步。(3)rsync命令可以直接使用:二·xsync命令作用:(1)使用xsync命令同步一个文件,会只将这个文件,同步到其他服务器的相同路径下面。(2)使

    2022年5月21日
    49
  • poj 2408 Anagram Groups(hash)

    poj 2408 Anagram Groups(hash)

    2022年1月2日
    39
  • journalctl工具基础介绍

    journalctl工具基础介绍journalctl工具是CentOS-7才有的工具Systemd统一管理所有Unit的启动日志。带来的好处就是,可以只用journalctl一个命令,查看所有日志(内核日志和应用日志)。日志的配置文件/etc/systemd/journald.confjournalctl用法查看所有日志(默认情况下,只保存本次启动的日志)journalctl查看内核日志(不显示应用日志)journalctl-k查看系统本次启动的日志

    2022年5月10日
    48
  • apache 负载均衡_nginx轮询策略配置

    apache 负载均衡_nginx轮询策略配置Apache负载均衡配置详解

    2025年10月17日
    5
  • sqlyog下载安装_sqlyog激活成功教程版

    sqlyog下载安装_sqlyog激活成功教程版地址:https://github.com/webyog/sqlyog-community/wiki/Downloads

    2022年9月23日
    2

发表回复

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

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