bjfu1281

时间:2023-03-09 01:25:15
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 ;
}