这个代码为什么不对啊
查看原帖
这个代码为什么不对啊
1077657
Devpp楼主2023/12/28 16:18
#include<iostream>
#include<vector>
using namespace std;
int num[10]{6,2,5,5,4,5,6,3,7,6};
int main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    long long r,l;  cin>>l>>r;
    if(r==l){
        cout<<1;
        return 0;
    }
    long long len=r-l+1;
    long long carry=l;
    vector<int> count(len,0);
    while(carry){
        count[0]+=num[carry%10];
        carry/=10;
    }
    long long counting=1,max=0;
    for(int i=1;i<len;++i){
        long long carry1=i+l;
        while(carry1){
            count[i]+=num[carry1%10];
            carry1/=10;
        }
        if(count[i]==count[i-1]){
            counting++;
        }else{
            if(counting>max){
                max=counting;
            }
            counting=1;
        }
    }

    if(counting==len){
        cout<<counting;
    }else{
        cout<<max;
    }
    return 0;
}
2023/12/28 16:18
加载中...