Nanyang Polytechnic---topic 975 about 521

Source: Internet
Author: User

About 521 time limit: + Ms | Memory Limit:65535 KB Difficulty:2
Describe

The ACM team's fleeting study of mathematics is not very thorough, but stubborn he still want to go in.

Browsing the Web page suddenly saw someone on the internet with rose petals to spell 521 Three numbers, suddenly feel good romantic, because every boy will inadvertently become a romantic maker. Since then, the time to go everywhere can see 5,2,1 Three numbers, he was angry, and now he wants to know how many of the consecutive number of the total contains the three numbers. For example 12356 even one, and 5111 is not counted. In particular, if he saw the 521 Three numbers in succession, there would be a special rage. such as 35210.

Input
multiple sets of test data:
A row is given a two number, A, B (0<a,b<1000000), which represents the start and end of a number.
Output
a row shows a few of the numbers he wants to know and shows how many figures make him particularly angry. separated by a space.
Sample input
200 500300 9001 600
Sample output
Case 1:2 0Case 2:2 1Case 3:6 1
Source
Fleeting
Uploaded by
acm_ Ann Pengcheng

Analysis: Direct solution is the code for the timeout timeout:

#include <iostream> #include <stdio.h> #include <string.h>using namespace Std;int main () {char a[100];    int n,m;    int k=1;        while (cin>>n>>m) {int t1=0;        int t2=0;        int b1,b2,b3;          for (int i=n;i<=m;i++) {b1=0;b2=0;b3=0;         sprintf (A, "%d", I);          Converts the integer i to the string int Len=strlen (a);                  for (int i=0;i<len;i++) {if (a[i]== ' 5 ' &&a[i+1]== ' 2 ' &&a[i+2]== ' 1 ')                    {t2++;                  Break                } if (a[i]== ' 5 ') b1=1;                if (a[i]== ' 2 ') b2=1;                if (a[i]== ' 1 ') b3=1;                    if (B1&AMP;&AMP;B2&AMP;&AMP;B3) {t1++;                Break        }}} printf ("Case%d:", k++);    printf ("%d%d\n", t1+t2,t2); } return 0;}
The correct code:

#include <iostream> #include <stdio.h> #include <string.h>using namespace std;struct dot{    int t1;    int T2;}; Dot A[1000050];int Main () {    int n,m;    int k=1;    int t1=0,t2=0;    memset (A,0,sizeof (a));    for (int i=100;i<1000000;i++)    {        if (i%10==1| | i/10%10==1| | i/100%10==1| | i/1000%10==1| | i/1000%10==1| | i/10000%10==1| | i/100000==1)               && (i%10==2| | i/10%10==2| | i/100%10==2| | i/1000%10==2| | i/1000%10==2| | i/10000%10==2| | i/100000==2)               && (i%10==5| | i/10%10==5| | i/100%10==5| | i/1000%10==5| | i/1000%10==5| | i/10000%10==5| | i/100000==5))                t1++;            if (i%1000==521| | i/10%1000==521| | i/100%1000==521| | i/1000==521)                t2++;                A[I].T1=T1;                a[i].t2=t2;    }    while (cin>>n>>m)    {        printf ("Case%d:%d%d\n", k++, (A[M].T1-A[N-1].T1), (A[M].T2-A[N-1].T2));    }    return 0;}


Nanyang Polytechnic---topic 975 about 521

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.