zoukankan      html  css  js  c++  java
  • 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 = 0; 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 < 3 || len % 2 == 0) {
            return false;
        }
        int d = len / 2;
        for (int i = 0; i < d; i++) {
            if (ss[i] != '1' || ss[len - i - 1] != '1') {
                return false;
            }
        }
        return true;
    }
    
    int lowercount(const char* ss, int len) {
        if (len < 3) {
            return 0;
        }
        if (len % 2 == 0) {
            return (len / 2 - 1) * 10;
        }
        if (judge(ss, len)) {
            return (len / 2 - 1) * 10 + ss[len / 2] - '0';
        }
        char str[2000];
        memset(str, '1', len);
        str[len] = 0;
        str[len / 2] = '0';
        if (lessthan(ss, str, len)) {
            return (len / 2 - 1) * 10;
        } else {
            return (len / 2 ) * 10;
        }
    }
    
    
    int main() {
    //    freopen("data.in", "r", stdin);
        char a[2000], b[2000];
        int T, lena, lenb;
        scanf("%d", &T);
        for (int t = 1; 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
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    在CentOS-6.9里安装openvswitch-2.5.4
    Django 2.0.7 使用小知识
    微信小程序 存储数据到本地以及本地获取数据
    微信小程序目录结构与配置介绍
    微信小程序视图层介绍及用法
    小程序 wx.request请求
    小程序的启动流程(生命周期)
    小程序的双线程模型
    小程序之基础组件
    小程序之路由跳转
  • 原文地址:https://www.cnblogs.com/moonbay/p/4279601.html
Copyright © 2011-2022 走看看