NYOJ-975-关于521

来源:互联网 发布:企业淘宝 编辑:程序博客网 时间:2024/05/21 09:02

关于521

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述

Acm队的流年对数学的研究不是很透彻,但是固执的他还是想一头扎进去。

浏览网页的流年忽然看到了网上有人用玫瑰花瓣拼成了521三个数字,顿时觉得好浪漫,因为每个男生都会不经意的成为浪漫的制造者。此后,流年走到哪里都能看到521三个数字,他怒了,现在他想知道在连续的数中有多少数全部包含了这三个数字。例如12356就算一个,而5111就不算。特别的,如果他看到了521三个数连续出现,会特别的愤怒。例如35210

输入
多组测试数据:
一行给定两个数a,b(0<a,b<1000000),表示数字的开始和结束。
输出
一行显示他想要知道的数有几个及显示有多少个数字令他特别的愤怒。用空格隔开。
样例输入
200 500300 9001 600
样例输出
Case 1:2 0Case 2:2 1Case 3:6 1
虽然运行很慢,但也是一种思想
 #include <iostream>#include <sstream>#include <malloc.h>using namespace std;const int MAXN = 999999;int main(){    int *d;    int *d1;    d = (int *)malloc(sizeof(int)*MAXN);    d1 = (int *)malloc(sizeof(int)*MAXN);    stringstream stream;    string s;    int ans = 0, flag = 0;    for(int i = 125; i <= MAXN; i++)    {        stream << i;        stream >> s;        if(s.find("5") != s.npos && s.find("2") != s.npos && s.find("1") != s.npos)        {            ans++;            if(i >= 521 && s.find("521") != s.npos)                flag++;        }        d[i] += ans;        d1[i] += flag;        stream.clear();    }    int a, b, c = 0;    while(cin >> a >> b)    {        c++;        cout << "Case " << c << ":" << d[b]-d[a-1] << " " << d1[b]-d1[a-1]<< endl;    }    free(d1);    free(d);    return 0;}        


0 0