Barbara Bennett's Wild Numbers
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 3153   Accepted: 1143

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?8
236428
8?3
910
?
5
#

Sample Output

100
0
4

Source

/*
回来的第一道题,几天不用脑子生锈了
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 20
using namespace std;
long long power(long long a,long long b)//类似于pow函数的一个功能,因为颇为太小了
{
long long ans=;
for(int i=;i<=b;i++)
ans*=;
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
char a[N],b[N];
while(scanf("%s",&a)!=EOF&&strcmp(a,"#")!=)
{
long long ans=;//计时器
int sum=,cur=;//计算问号的次数和枚举目前为止出现问号的次数
scanf("%s",&b);
for(int i=;a[i];i++)
if(a[i]=='?')
sum++;
for(int i=;a[i];i++)
{
if(a[i]!='?')
{
if(a[i]>b[i])
{
ans+=power(,sum-cur);
break;
}
else if(a[i]<b[i])
break;
}
else if(a[i]=='?')
{
cur++;
ans+=power(,sum-cur)*(-b[i]+'');
}
}
printf("%lld\n",ans);
}
return ;
}

poj 3340 Barbara Bennett's Wild Numbers(数位DP)的更多相关文章

  1. hdu 2410 Barbara Bennett's Wild Numbers

    Problem - 2410 挺好玩的一道题目.这道题的意思是给出一个模糊值以及一个确定值,要求求出模糊值中大于确定值的个数有多少. 这题我是直接用dfs的方法搜索的,对于每一位如果之前位置的形成的数 ...

  2. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  3. poj 3252 Round Numbers(数位dp 处理前导零)

    Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...

  4. POJ 3252 Round Numbers(数位dp&amp;记忆化搜索)

    题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于 ...

  5. poj 3252 Round Numbers 数位dp

    题目链接 找一个范围内二进制中0的个数大于等于1的个数的数的数量.基础的数位dp #include<bits/stdc++.h> using namespace std; #define ...

  6. $POJ$3252 $Round\ Numbers$ 数位$dp$

    正解:数位$dp$ 解题报告: 传送门$w$ 沉迷写博客,,,不想做题,,,$QAQ$口胡一时爽一直口胡一直爽$QAQ$ 先港下题目大意嗷$QwQ$大概就说,给定区间$[l,r]$,求区间内满足二进制 ...

  7. POJ3252 Round Numbers —— 数位DP

    题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Su ...

  8. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

随机推荐

  1. java 读取properties文件总结

    一.java读取properties文件总结 在java项目中,操作properties文件是经常要做的,因为很多的配置信息都会写在properties文件中,这里主要是总结使用getResource ...

  2. java集合系列——List集合之Vector介绍(四)

    1. Vector的简介 JDK1.7.0_79版本 Vector 类可以实现可增长的对象数组.与数组一样,它包含可以使用整数索引进行访问的组件.但是,Vector 的大小可以根据需要增大或缩小,以适 ...

  3. HDFS源码分析之NameNode(3)————RpcServer

    NameNodeRpcServer implements NamenodeProtocols NameNode支持核心即NameNodeRpcServer 实现ClientProtocol  支持客户 ...

  4. [js高手之路] javascript面向对象写法与应用

    一.什么是对象? 对象是n个属性和方法组成的集合,如js内置的document, Date, Regexp, Math等等 document就是有很多的属性和方法, 如:getElementById, ...

  5. Jmeter连接mysql数据库

    1.下载 MySQL JDBC driver,并拷贝到jmeter的lib目录下. 2.创建JDBC Connection Configuration 需要填入的信息: Variable Name:M ...

  6. MVC中Controller控制器相关技术

    第6章Controller相关技术 Controller(控制器)在ASP.NET MVC中负责控制所有客户端与服务器端的交互,并 且负责协调Model与View之间的数椐传递,是ASP.NET MV ...

  7. Jquery+Ajax限制查询间隔

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Jquery20150305.a ...

  8. 运维&网络知识(一)

    1. DNS 域名系统(Domain Name System),因特网上作为域名和IP地址映射的一个分布式数据库.

  9. 解决 Win10 UWP 无法使用 ss 连接

    一旦使用了 ss, 那么很多应用就无法连接网络. 本文提供一个方法可以简单使用ss提供的代理. 多谢 wtwsgs 提供方法:http://blog.csdn.net/wtwsgs/article/d ...

  10. win10 uwp 分治法

    其实我想说Path,因为最近在做一个简单的分治. 算法涉及到了一个平面几何的知识.就是三角形p1p2p3的面积等于以下行列式的二分之一: 而且当点P3 在射线P1P2的左侧的时候,表达式为正,右侧表达 ...