Codeforces Round #129 (Div. 2) C

Description

The Little Elephant very much loves sums on intervals.

This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and47, 253 or 1020 will not.

Help him and count the number of described numbers x for a given pair l and r.

Input

The single line contains a pair of integers l and r (1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64dspecifier.

Output

On a single line print a single integer — the answer to the problem.

Examples
input
2 47
output
12
input
47 1024
output
98
Note

In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.

题意:有这种数字,第一位和最后一位相同,问你两个数字范围内有多少符合要求的数字~

解法:当然是找规律啊,很容易看出规律是9*10^n,然后考虑两个端点的情况,他们是不是也是符合要求的(这里的代码写的不清楚QAQ,最有价值的只有cmd函数了)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<bits/stdc++.h>
using namespace std;
long long a[100005];
int pos;
int n;
int d;
long long cmd(string s)
{
    long long sum1=0,sum2=0;
    if(s.length()==1)
    {
        sum1=0;
    }
    else if(s.length()==2)
    {
        sum1=9;
    }
    else
    {
        sum1=10;
        for(int i=1;i<s.length()-2;i++)
        {
            sum1*=10;
        }
     //   cout<<sum1<<endl;
        sum1=sum1-1;
      //  cout<<sum1<<endl;
        sum1+=9;
 
    }
    int ans1=s[0]-'0'-1;
    long long sum3=0;
    long long pos1=1;
    if(s.length()>=3)
    {
        for(int i=1; i<=s.length()-2; i++)
        {
            sum3=sum3*10+(s[i]-'0');
        }
       // sum3=sum3+1;
        for(int i=0; i<s.length()-2; i++)
        {
            pos1*=10;
        }
        if((s[0]-'0')<=(s[s.length()-1]-'0'))
        {
            sum1=sum1+ans1*pos1+sum3+1;
        }
        else
        {
            sum1=sum1+ans1*pos1+sum3;
        }
 
    }
    else
    {
        if(s[0]<=s[s.length()-1])
        {
            sum1=sum1+ans1*pos1+sum3+1;
        }
        else
        {
            sum1=sum1+ans1*pos1+sum3;
        }
    }
    return sum1;
}
int main()
{
    string s1,s2;
    cin>>s1>>s2;
   // cout<<cmd(s1)<<endl;
   // cout<<cmd(s2)<<endl;
    if(s1[0]==s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)+1<<endl;
    }
    else if(s1[0]==s1[s1.length()-1]&&s2[0]>s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)+1<<endl;
    }
    else if(s1[0]<=s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)<<endl;
    }
    else if(s1[0]<=s1[s1.length()-1]&&s2[0]>s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)<<endl;
    }
    else if(s1[0]>s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)<<endl;
    }
    else if(s1[0]>s1[s1.length()-1]&&s2[0]>s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)<<endl;
    }
    else if(s1[0]>s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
    {
        cout<<cmd(s2)-cmd(s1)<<endl;
    }
    return 0;
}

  

posted @   樱花落舞  阅读(265)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示