题目链接:

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?

8
236428
8?3
910
?
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;
}

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)的更多相关文章

  1. hdu 2410 Barbara Bennett's Wild Numbers

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

  2. poj 3340 Barbara Bennett's Wild Numbers(数位DP)

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

  3. POJ 3344 &amp; HDU 2414 Chessboard Dance(模拟)

    题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...

  4. POJ 3831 &amp; HDU 3264 Open-air shopping malls(几何)

    题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...

  5. POJ 3691 &amp; HDU 2457 DNA repair (AC自己主动机,DP)

    http://poj.org/problem?id=3691 http://acm.hdu.edu.cn/showproblem.php?pid=2457 DNA repair Time Limit: ...

  6. POJ 3481 &amp; HDU 1908 Double Queue (map运用)

    题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...

  7. POJ 3835 &amp; HDU 3268 Columbus’s bargain(最短路 Spfa)

    题目链接: POJ:http://poj.org/problem?id=3835 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3268 Problem ...

  8. POJ 3928 &amp; HDU 2492 Ping pong(树阵评价倒数)

    主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...

  9. ●线段树的三个题(poj 3225,hdu 1542,hdu 1828)

    ●poj 3225 Help with Intervals(线段树区间问题) ○赘述题目 给出以下集合操作: 然后有初始的一个空集S,和以下题目给出的操作指令,并输入指令: 要求进行指令操作后,按格式 ...

随机推荐

  1. QWidget类中默认是忽略inputMethodEvent事件(要获取输入的内容就必须使用这个事件)

    因为项目的需要以及主管的要求,准备将工程移植到Qt中,这样就可以比较容易的实现跨平台了.因为之前工程是在windows下开发的,第一个平台又是mobile所以除了底层框架之外其他的都是使用的windo ...

  2. 在TC(Total Commander)中添加启动Cygwin快捷键的方法

    在TC(Total Commander)中添加启动Cygwin快捷键的方法 1.在Cygwin的安装目录下,增加文件tc-cygwin.bat(例如C:\cygwin-177\tc-cygwin.ba ...

  3. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'xxxx'@''

    这两天项目一直在报这个错误消息: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to ...

  4. python手记(27)

    #!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" ...

  5. 高焕堂《android从程序员到架构师之路》 YY讲坛直面大师学习架构设计

    <android从程序员到架构师之路>YY讲坛活动:  sundy携手高焕堂老师全程YY答疑 与大师一起,分享android技术 时间:7月21日下午2:00   报名联系QQ:22243 ...

  6. Android ListView条目全选功能,不用checkbox实现!

    大家好,翻了翻曾经的笔记,发现了一个我特别标记的功能,那就是ListView全选功能,顿时想起了我那个时候苦逼的生涯,因为我大学机械出身,大学毕业了都不知道什么叫代码,在58干了一段销售.实在是干不下 ...

  7. C#拖曳控件加载,bll报错问题

    C#拖曳控件加载,bll报错问题,加载时实例如化bll时加上一个判断 if (!(GetService(typeof(IDesignerHost)) != null            || Sys ...

  8. 1数组的join方法

    function log(e) { console.log(e) } 有时候写console.log太长了,所以会自己写个这样的函数省去写console的步骤. 数组的join方法可以把一个数组按照j ...

  9. 解决Java compiler level does not match the version of the installed Java project facet.问题

    其实之前遇到过Java compiler level does not match the version of the installed Java project facet.这个问题,因为当时没 ...

  10. delphi中无类型文件读写

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...