现在的位置: 首页 > 综合 > 正文

hdu 2089

2013年08月20日 ⁄ 综合 ⁄ 共 482字 ⁄ 字号 评论关闭

不想用循环做,用了STL。。

题目链接

#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
using namespace std;
int m[1000005];
int main()
{
    int n,i,j,len,t1,t2;
    m[0]=0;
    char s[10];
    stringstream str;
    for(i=1;i<1000000;i++)
    {
        str.clear();
        str<<i;
        str>>s;
        len=strlen(s);
        for(j=0;j<len;j++)
        {
            if(s[j]=='4'||(s[j]=='6'&&s[j+1]=='2'))
            {
                m[i]=m[i-1];break;
            }
        }
        if(j==len) m[i]=m[i-1]+1;
    }
    while(scanf("%d%d",&t1,&t2))
    {
        if(!t1&&!t2) break;
        if(m[t1]!=m[t1-1])
        printf("%d\n",m[t2]-m[t1]+1);
        else printf("%d\n",m[t2]-m[t1]);
    }
    return 0;
}

抱歉!评论已关闭.