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,和以下题目给出的操作指令,并输入指令: 要求进行指令操作后,按格式 ...
随机推荐
- Android 计时与倒计时
方法一 Timer与TimerTask(Java实现) [java] view plain copy print ? public class timerTask extends Activit ...
- office文档转pdf
这里贴下代码吧,没啥好说的. using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 根据input 标签取value属性的值
jrhmpt01:/root/lwp/0526# cat a1.pl use LWP::UserAgent; use DBI; use POSIX; use Data::Dumper; use HTM ...
- 发掘ListBox的潜力(二):鼠标拖放插入点提示
鼠标拖放插入点提示 鼠标拖放是Windows常见的操作,比如拷贝文件就可用拖放方式进行.在我们编写的应用程序中,有时为了方便用户操作需要支持鼠标拖放.对于大部分的VCL控件只要鼠标将DragMode设 ...
- Scanner类及正则表达式
import java.util.Scanner; public class ScannerToString { public static void main(String[] args) { Sc ...
- mysql基础:mysql列类型--时间和日期
mysql列类型--整型 http://blog.csdn.net/jk110333/article/details/9342283 mysql列类型--字符串http://blog.csdn.net ...
- kgdb调试注意事项
0 首先提下注意事项的背景: kgdb和printk共用一个串口 1 设置波特率: //最高支持460800波特率 arm-eabi-gdb ./vmlinux ...
- [置顶] Objective-C ,ios,iphone开发基础:命名规范
命名规范:http://bukkake.iteye.com/blog/695492 点击打开链接
- 【Unity3D自学记录】Unity3D网络之Socket聊天室初探
首先创建一个服务端程序,这个程序就用VS的控制台程序做即可了. 代码例如以下: using System; using System.Collections.Generic; using System ...
- Linux编程实现守护进程
Linux 守护程序 守护进程(Daemon)它是在一个特定的过程的背景进行.它独立于控制终端的和周期性地执行某些任务或待某些事件.是一种非常实用的进程. Linux的大多数server就是用守护进程 ...