Advertisement
Nbrevu

Tuenti Contest 11 (Pablo Moreno)

Jun 20th, 2011
1,524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /*
  2.     Author: Pablo Moreno Olalla
  3.     Email address: darthbrevu@yahoo.es
  4. */
  5. #include <cstdio>
  6. #include <string>
  7. #include <sstream>
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12. string ns="No stops";
  13.  
  14. int main(int argc,char **argv)  {
  15.     //The first two lines are not strictly necessary, but make the code a little more handy.
  16.     if (argc>=2) freopen(argv[1],"r",stdin);
  17.     if (argc>=3) freopen(argv[2],"w",stdout);
  18.     string tmp;
  19.     unsigned int N,capacity,total,gs;
  20.     unsigned int prev,next;
  21.     unsigned int until;
  22.     getline(cin,tmp);
  23.     if (sscanf(tmp.c_str(),"%u",&N)!=1) return -1;
  24.     for (size_t i=0;i<N;++i)    {
  25.         bool ws=false;
  26.         int current;
  27.         getline(cin,tmp);
  28.         if (sscanf(tmp.c_str(),"%u",&capacity)!=1) return -1;
  29.         getline(cin,tmp);
  30.         if (sscanf(tmp.c_str(),"%u",&total)!=1) return -1;
  31.         getline(cin,tmp);
  32.         if (sscanf(tmp.c_str(),"%u",&gs)!=1) return -1;
  33.         getline(cin,tmp);
  34.         if (gs>1)   {   //Always, probably. But let's ensure it ;).
  35.             istringstream iss(tmp);
  36.             iss>>prev;
  37.             until=capacity;
  38.             for (size_t j=1;j<gs;++j)   {
  39.                 iss>>next;
  40.                 if (iss.fail()) return -1;
  41.                 if (next>until) {
  42.                     if (ws) cout<<' ';
  43.                     cout<<prev;
  44.                     ws=true;
  45.                     until=capacity+prev;
  46.                 }
  47.                 prev=next;
  48.             }
  49.             if (until<total)    {
  50.                 if (ws) cout<<' ';
  51.                 cout<<next;
  52.                 ws=true;
  53.             }
  54.             if (!ws) cout<<ns;
  55.             cout<<endl;
  56.         }
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement