关于521
描述
Acm队的流年对数学的研究不是很透彻,但是固执的他还是想一头扎进去。
浏览网页的流年忽然看到了网上有人用玫瑰花瓣拼成了521三个数字,顿时觉得好浪漫,因为每个男生都会不经意的成为浪漫的制造者。此后,流年走到哪里都能看到5、2、1三个数字,他怒了,现在他想知道在连续的数中有多少数全部包含了这三个数字。例如12356就算一个,而5111就不算。特别的,如果他看到了521三个数连续出现,会特别的愤怒。例如35210。
输入
多组测试数据:
一行给定两个数a,b(0<a,b<1000000),表示数字的开始和结束。
输出
一行显示他想要知道的数有几个及显示有多少个数字令他特别的愤怒。用空格隔开。
样例输入
200 500
300 900
1 600
样例输出
Case 1:2 0
Case 2:2 1
Case 3:6 1
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#define MAX 1000010
int s1[MAX],s2[MAX];
char ch[20];
using namespace std;
void temp(int x);
int judge();
int main()
{
int k;
for(int i=125;i<MAX;i++)
{
temp(i);
k=judge();
if(k==2)
{
s1[i]=s1[i-1]+1;
s2[i]=s2[i-1]+1;
}
else if(k==1)
{
s1[i]=s1[i-1]+1;
s2[i]=s2[i-1];
}
else
{
s1[i]=s1[i-1];
s2[i]=s2[i-1];
}
}
int a,b,x=0;
while(cin>>a>>b)
{
cout<<"Case "<<++x<<":"<<s1[b]-s1[a-1]<<" "<<s2[b]-s2[a-1]<<endl;
}
return 0;
}
void temp(int x)
{
int i=0;
while(x)
{
ch[i++]=x%10+'0';
x/=10;
}
ch[i]='\0';
}
int judge()
{
if(strstr(ch,"125"))
return 2;
else if(strchr(ch,'1')&&strchr(ch,'2')&&strchr(ch,'5'))
return 1;
return 0;
}