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


相关推荐

  • route命令详解

    route命令详解route命令详解在网络中,route命令用来显示、添加、删除和修改网络的路由。1.route命令的格式route[-f][-p][Command][Destination][maskNetmask][Gateway][metricMetric][ifInterface]2.route-参数的含义:route-f:用于清除路由表。route-p:用于创建永久路由。routeComman:主要有print(打印路由)、ADD(添加路由)、DELETE(删

    2022年7月18日
    28
  • 基于协同过滤的电影推荐系统的设计与实现(协同过滤推荐算法伪代码)

    1Mahout介绍ApacheMahout是ApacheSoftwareFoundation(ASF)旗下的一个开源项目,提供一些可扩展的机器学习领域经典算法的实现,旨在帮助开发人员更加方便快捷地创建智能应用程序。经典算法包括聚类、分类、协同过滤、进化编程等等,并且,在Mahout中还加入了对ApacheHadoop的支持,使这些算法可以更高效的运行在云计算环境中。…

    2022年4月11日
    322
  • IDEA超级实用的几个快捷键[通俗易懂]

    最近开始使用IDEA,突然发现的比较的实用的几个快捷键 这些快捷键用的好的话真的可以提升很多效率 还有一些比较简单的快捷键,相信大家都会 Ctrl+X:剪切 Ctrl+C:复制 Ctrl+V:粘贴 C

    2022年3月13日
    40
  • C++ offsetof

    C++ offsetof这是一个宏,用于计算类中某个成员的地址相对于类实例的偏移量在C++11中,要求这个类standard_layout基本用法是这样子的:#include<stdio.h>/*printf*/#include<stddef.h>/*offsetof*/structfoo{chara;ch…

    2022年8月22日
    5
  • java抽象语法树(ast),AST 抽象语法树

    java抽象语法树(ast),AST 抽象语法树AST 抽象语法树简介 AST AbstractSynt 是源代码的抽象语法结构树状表现形式 Webpack ESLint JSX TypeScript 的编译和模块化规则之间的转化都是通过 AST 来实现对代码的检查 分析以及编译等操作 JavaScript 语法的 AST 语法树 JavaScript 中想要使用 AST 进行开发 要知道抽象成语法树之后的结构是什么 里面的字段名称

    2026年3月17日
    2
  • Ubuntu安装和配置ssh教程

    Ubuntu安装和配置ssh教程一般 Ubuntu 都会默认安装 openssh client 但是没有安装 openssh server 安装 ssh 服务器 sudoaptinsta server 安装 ssh 客户端 sudoaptinsta client nbsp nbsp 配置 ssh 客户端 去掉 PasswordAuth 前面的 号 保存退出 su

    2026年3月18日
    2

发表回复

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

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