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
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 <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 & HDU 2410 Barbara Bennett's Wild Numbers(数学)的更多相关文章
- hdu 2410 Barbara Bennett's Wild Numbers
Problem - 2410 挺好玩的一道题目.这道题的意思是给出一个模糊值以及一个确定值,要求求出模糊值中大于确定值的个数有多少. 这题我是直接用dfs的方法搜索的,对于每一位如果之前位置的形成的数 ...
- poj 3340 Barbara Bennett's Wild Numbers(数位DP)
Barbara Bennett's Wild Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3153 A ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...
- POJ 3691 & 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: ...
- POJ 3481 & HDU 1908 Double Queue (map运用)
题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...
- POJ 3835 & HDU 3268 Columbus’s bargain(最短路 Spfa)
题目链接: POJ:http://poj.org/problem?id=3835 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3268 Problem ...
- POJ 3928 & HDU 2492 Ping pong(树阵评价倒数)
主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...
- ●线段树的三个题(poj 3225,hdu 1542,hdu 1828)
●poj 3225 Help with Intervals(线段树区间问题) ○赘述题目 给出以下集合操作: 然后有初始的一个空集S,和以下题目给出的操作指令,并输入指令: 要求进行指令操作后,按格式 ...
随机推荐
- js中使用jstl中得到的值
jstl的标签会转化为服务器端的代码执行,而js代码则在客户端执行. 要在js中使用jstl并不是直接将jstl的value赋值给一个js的变量,而是要在jstl的value上加上&qu ...
- NSUserDefaults设置bool值重新启动后bool仅仅设置丢失问题
今天使用NSUserDefaults保存bool至重新启动后发现bool值没有保存对 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults ...
- CorePlot学习零---安装
刚開始接触CorePlot时,网上搜到非常多相关文章,解说怎样安装这个第三方库,到眼下阶段该库的版本号已经到了1.5了,可是在github上你能够看到他的安装方法,只是为啥就没有codpod来安装呢? ...
- 使用POI创建Excel文件下载
POIExcelUtils.java: package com.saicfc.pmpf.internal.manage.utils; import java.io.File; import java. ...
- µC/OS-II版本升级指南
IDE: MDK V4+ MCU: LPC17xx(Cortex-M3) RTOS: µC/OS-II 升级顺序:V2.52->V2.62->V2.76-> ...
- Eclipse用法和技巧八:自动添加try/catch块1
站在编译器的角度来看,java中的异常可以分为两种,已检查异常和未检查异常.对于已检查异常比如IO操作,编译器会要求设置try/catch语句块,在eclipse中也只要使用帮助快捷键ctrl+1,就 ...
- Cookie例子
马士兵老师的~~ cookie是服务器将信息保存在客户端的一个表示方式 名-值 服务器只能写入文档文件 每个浏览器都有唯一的标识号 且每个浏览器只允许访问与自身相关的cookie的内容 cookie分 ...
- android 细节之 旋转动画
Flip Animation for Android: 近期项目中用到了一个小动画,让物体实现一定的3D旋转效果,现记录例如以下: public class FlipAnimation extends ...
- MSSQL - 用GUID值来完成数据表行标识
地址:http://www.cnblogs.com/huangfr/archive/2012/03/28/2420780.html [Guid] [uniqueidentifier] NOT NULL ...
- 使用OVS
创建节点: 需要在组件上引用OVS组件WDR_OVS:引用后需要更改添加节点属性值如下: 布局如下: 在view中也添加ovs组件 新建事件方法: ON_EVENT 代码如下: METHOD on_e ...