Life, the Universe, and Everything (SPOJ)

Source: Internet
Author: User

Original title: Your program was to use the brute-force approach in order to find the Answer to life, the Universe, and everything.< /c1> more precisely ... rewrite small numbers from input to output. Stop processing input After reading in the number 42. All numbers at input is integers of one or both digits.

Example

 Input:12884299Output:1288
The problem is simple, just repeat the small number (int is enough), once you receive theThe numbers stop receiving, the example of the topic here is misleading, easy to understand as all input (and then CTRL + Z to end the input), and then output the first meeting 42 o'clock, before 42 all the numbers, why I know, because I have so submitted once
The main difficulty of this problem is that you do not know how many numbers to enter before encountering 42, the topic does not give any constraints, it is obvious that the array, stack and the like to allocate the size of the memory space, and finally through the vector in C + + solve the problem.
a vector is a class template that the vector holds which object type is specified by placing the type in angle brackets after the class template name vector<int>iver; vector<char> VEC;
The only reason to use vectors is that vector objects can add elements dynamically at runtime, without the need to allocate memory directly and avoid unnecessary waste.
A brief introduction to several commonly used vector object operations:
  
1.push_back add a data at the end of the array
2.pop_back remove the last data from the array
3.at get the data of the numbered position
4.begin get pointer to array header
5.end gets the pointer to the last cell +1 of the array
In addition to accessing vector object elements by subscript, they can also be accessed through iterators. An iterator is a data type that examines the elements inside a container and traverses the elements.
Each iterator defines its own type,
such as vector<int>::iterator it;
the other is not elaborate, on the code:
1#include <iostream>2#include <stdio.h>3#include <vector>4 using namespacestd;5 intMain ()6 {7     intNumber ;8vector<int>Vec;9      while(cin>>Number )Ten     { One         if(number!= the) A vec.push_back (number); -         Else  -              Break; the     } -vector<int>:: iterator it; -      for(It=vec.begin ();    It!=vec.end (); it++) -cout<< *it <<Endl; +          -     return 0; +}

Operation Result:

  


  

Life, the Universe, and Everything (SPOJ)

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.