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. Swift中的参数内部名称和外部名称

    1.什么是参数的内部名称和外部名称? struct Color { let red, green, blue: Double init(red redColor: Double,green green ...

  2. Guava手记

    Cache Guava的Cache封装的功能比较全面,但是很多地方和设想的不太一样,最明显的就是RemovalListener,它并不是invalid之后就会被调用,因为在调用Cache的invali ...

  3. 【转】 Pro Android学习笔记(二七):用户界面和控制(15):FrameLayout

    FrameLayout FrameLayout通常只包含一个控件.如果我们在FrameLayout中设置多个控件,则第二个控件会堆叠在第一个控件上面,如此类推,一层一层地叠上去.下面的例子,我们在Fr ...

  4. spark提交模式

    spark基本的提交语句: ./bin/spark-submit \ --class <main-class> \ --master <master-url> \ --depl ...

  5. svn、git等比较---总结

    免费的版本控制系统: CVS:集中式的版本控制系统,必须联网,速度慢,CVS作为最早的开源而且免费的集中式版本控制系统,直到现在还有不少人在用.由于CVS自身设计的问题,会造成提交文件不完整,版本库莫 ...

  6. Weblogic反序列化漏洞(CVE-2017-10271)复现

    通过POST发送xml数据对WebLogic Server组件的WLS Security子组件造成任意代码执行漏洞 影响版本:10.3.6.0.0,12.1.3.0.0,12.2.1.1.0,12.2 ...

  7. kafka 基础知识梳理(转载)

    一.kafka 简介 kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据.这种动作(网页浏览,搜索和其他用户的行动)是在现代网络上的许多社会功能的一个关键因 ...

  8. linux压缩包安装jdk

    1.下载jdk压缩包 $ wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa00 ...

  9. shell判断网络主机存活

    判断网络主机存活企业面试题4:写一个脚本,实现判断10.0.0.0/24网络里,当前在线用户的IP有哪些(方法有很多) #!/bin/sh#[ -f /etc/init.d/functions ] & ...

  10. 微信小程序--录制音频,播放音频

    1.在pages创建一个main文件夹2.在main文件夹下创建一个miain.js文件.添加代码: const constant = require('../../utils/constant.js ...