bjfu1281
思路挺简单的,但因为需要处理大数,所以就比较耗代码了。
/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std; //比较两个数s1和s2的大小,当s1<s2时返回真
bool lessthan(const char* s1, const char* s2, int len) {
for (int i = ; i < len; i++) {
if (s1[i] < s2[i]) {
return true;
} else if (s1[i] > s2[i]) {
return false;
}
}
return false;
} //检测是否栅栏数
bool judge(const char* ss, int len) {
if (len < || len % == ) {
return false;
}
int d = len / ;
for (int i = ; i < d; i++) {
if (ss[i] != '' || ss[len - i - ] != '') {
return false;
}
}
return true;
} int lowercount(const char* ss, int len) {
if (len < ) {
return ;
}
if (len % == ) {
return (len / - ) * ;
}
if (judge(ss, len)) {
return (len / - ) * + ss[len / ] - '';
}
char str[];
memset(str, '', len);
str[len] = ;
str[len / ] = '';
if (lessthan(ss, str, len)) {
return (len / - ) * ;
} else {
return (len / ) * ;
}
} int main() {
// freopen("data.in", "r", stdin);
char a[], b[];
int T, lena, lenb;
scanf("%d", &T);
for (int t = ; t <= T; t++) {
scanf(" %s %s", a, b);
lena = strlen(a);
lenb = strlen(b);
int ans = lowercount(b, lenb) - lowercount(a, lena);
if (judge(b, lenb)) {
ans++;
}
printf("%d\n", ans);
}
return ;
}
bjfu1281的更多相关文章
随机推荐
- MSChart 控件
微软发布了.NET 3.5框架下的图表控件,功能很强劲,基本上能想到的图表都可以使用它绘制出来,给图形统计和报表图形显示提供了很好的解决办法,同时支持Web和WinForm两种方式,不过缺点也比较明显 ...
- bootstrap table 服务器端分页例子
1,前台引入所需的js 可以从官网上下载 function getTab(){ var url = contextPath+'/fundRetreatVoucher/fundBatchRetreatV ...
- git常见操作--忽略文件以及常用命令【转】
转自:http://www.cnblogs.com/elfsundae/archive/2011/07/17/2099698.html References: http://stackoverflow ...
- Android 代码监控apk安装,卸载,替换
public class GetBroadcast extends BroadcastReceiver { private static GetBroadcast mReceiver = new Ge ...
- C#图片压缩的实现方法
一般在web应用中,对客户端提交上来的图片肯定需要进行压缩的.尤其是比较大的图片,如果不经过压缩会导致页面变的很大,打开速度比较慢,当然了如果是需要高质量的图片也得需要生产缩略图. 一般在web应用中 ...
- BZOJ 1507 Editor(块状链表)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1507 题意:一个文本编辑器,模拟以下操作: 思路:块状链表的主要操作: (1)find( ...
- HDU 2149 (巴什博奕) Public Sale
没什么好说的,一道水题. #include <cstdio> int main() { int n, m; ) { if(n <= m) { for(int i = n; i < ...
- UVa 101 The Blocks Problem
题意:给出从左到右放置的n块木块(从0开始编号),再给出四种操作,再给出相应的操作,输出操作结束后每一堆木块的情况. 学习的紫书,因为每一堆的木块数是在发生变化的,所以用vector. 然后就是模拟几 ...
- PHP常见框架
PHP是一种在国内外都比较流行的开源服务器端脚本开发语言.能够适应大中小型项目的开发需求.我们将在这篇文章中向大家介绍几款主流PHP框架及其相关优缺点评比,作为一个参考分享给朋友们. 主要参考的PHP ...
- hdu 1885 Key Task(bfs+位运算)
题意:矩阵中'#'表示墙,'.'表示通路,要求从起点'*'到达终点'X',途中可能遇到一些门(大写字母),要想经过,必须有对应的钥匙(小写字母).问能否完成,若能,花费的时间是多少. 分析:同hdu ...