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函数了)

#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;
}

  

Codeforces Round #129 (Div. 2) C的更多相关文章

  1. Codeforces Round #129 (Div. 2)

    A. Little Elephant and Rozdil 求\(n\)个数中最小值的个数及下标. B. Little Elephant and Sorting \[\sum_{i=1}^{n-1}{ ...

  2. 字符串(后缀自动机):Codeforces Round #129 (Div. 1) E.Little Elephant and Strings

    E. Little Elephant and Strings time limit per test 3 seconds memory limit per test 256 megabytes inp ...

  3. Codeforces Round #129 (Div. 1)E. Little Elephant and Strings

    题意:有n个串,询问每个串有多少子串在n个串中出现了至少k次. 题解:sam,每个节点开一个set维护该节点的字符串有哪几个串,启发式合并set,然后在sam上走一遍该串,对于每个可行的串,所有的fa ...

  4. Codeforces Round #129 (Div. 2) B

    Description The Little Elephant loves sortings. He has an array a consisting of n integers. Let's nu ...

  5. Codeforces Round #129 (Div. 2) A

    Description The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. &quo ...

  6. Educational Codeforces Round 129 (Rated for Div. 2) A-D

    Educational Codeforces Round 129 (Rated for Div. 2) A-D A 题目 https://codeforces.com/contest/1681/pro ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. Unity3d中SendMessage 用法

      Message相关有3条指令:SendMessage ("函数名",参数,SendMessageOptions) //GameObject自身的ScriptBroadcastM ...

  2. [转]七个对我最好的职业建议(精简版)--Nicholas C. Zakas

    一.不要别人点什么,就做什么 我的第一份工作,只干了8个月,那家公司就倒闭了.我问经理,接下来我该怎么办,他说: "小伙子,千万不要当一个被人点菜的厨师,别人点什么,你就烧什么.不要接受那样 ...

  3. 编译Python出现Tab,空格的问题

    我们编译python代码时, 经常出现各种因为tab和空格的问题, 例如: IndentationError: unindent does not match any outer indentatio ...

  4. python 3中对list进行sort时,返回值为None

    进行在用python的list结构时, 发现一个问题: methods = [&apos;blogger.deletePost&apos;, &apos;blogger.get ...

  5. JavaScript跳转和打开新窗口

    跳转: window.location.href = "www.baidu.com"  // 跳转到百度首页,不打开新的浏览器窗口 等价于html中的<a href=&quo ...

  6. 没办法,SVD就讲的这么好

    2)奇异值: 下面谈谈奇异值分解.特征值分解是一个提取矩阵特征很不错的方法,但是它只是对方阵而言的,在现实的世界中,我们看到的大部分矩阵都不是方阵,比如说有N个学生,每个学生有M科成绩,这样形成的一个 ...

  7. linux日常管理-rsync_ssh方式

    现在我们有两台机器,两台机器都需要安装rsync    yum -y install rsync       一台的主机名是wangshaojun IP是192.168.1.117 ,另一台的主机名是 ...

  8. mouseenter与mouseover的区别

    mouseover 事件:只有在鼠标指针穿过被选元素时,才会触发. mouseover 事件:鼠标指针穿过任何子元素,都会触发. 请看例子的演示.

  9. SpringBoot02 Controller的使用、数据库操作、事物管理、修改banner

    1 Controller的使用 特点:编程技巧和SpringMVC几乎完全一样 注意:@RestController = @Controller + @ResponseBody 注意:读取路径参数和请 ...

  10. 树莓派 Learning 002 装机后的必要操作 --- 01 解决上网问题

    树莓派 装机后的必要操作 - 解决上网问题 我的树莓派型号:Raspberry Pi 2 Model B V1.1 装机系统:NOOBS v1.9.2 树莓派 装机后的必要操作 解决上网问题 解决上网 ...