PAT L1 041 Search 250

Source: Internet
Author: User

Title Description:

The other person doesn't want to talk to you and throws a bunch of numbers at you ... And you have to find the "250" on this big moving number from this string of numbers.

input Format:

Enter an integer in a row that does not know how many absolute values do not exceed 1000, which guarantees that at least one "250" exists.

output format: The

first occurrence of "250" in a row is the number that the opponent throws (counting starts from 1). The title guarantees that the number of outputs is within the integral type range.

Input Example:
888 666 123-233 250-222
Output Sample:
5

I don't know how many of the questions. That's what you have to do with the get string simulation, and then start with the first one, if it's not a space

ans=ans*10+a[i]-' 0 ';

If it is a space, this number is over, judging whether it is 250

if (a[i]== ') {
      //cout<< "  " <<ans<<endl;
      count++;
      if (ans==250) {
        answer=count;
        flag=0;
      }
      ans=0;
    }

That's probably what it means.

The complete code is as follows:

 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring > #include <iostream> #include <algorithm> #include <queue> #include <map> #include <stack
> #include <set> using namespace std;
typedef long Long LL;

typedef unsigned long long ull;
Char a[1000000];
    int main () {Ios::sync_with_stdio (false);
    Gets (a);
    ll Len=strlen (a);
    ll Ans=0;
    ll count=0;
    ll Answer=1;
    ll Flag=1;
            for (ll i=0;i<len&&flag;i++) {if (a[i]== ') {//cout<< "" <<ans<<endl;
            count++;
                if (ans==250) {answer=count;
            flag=0;
        } ans=0;
        } else{ans=ans*10+a[i]-' 0 ';
    }} if (ans==250) Answer=++count;
    cout<<answer<<endl;
return 0; }

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.