Nbrevu

Tuenti Contest 9 (Pablo Moreno)

Jun 20th, 2011
998
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Author: Pablo Moreno Olalla
  3.     Email address: darthbrevu@yahoo.es
  4. */
  5. #include <cstdio>
  6. #include <string>
  7. #include <vector>
  8. #include <sstream>
  9. #include <iostream>
  10. #include <algorithm>
  11.  
  12. using namespace std;
  13.  
  14. //This is an extremely simple problem!!
  15.  
  16. string noLights="All lights are off :(";
  17.  
  18. void solve(unsigned long I,unsigned long t,string &out) {
  19.     if (t==0)   {
  20.         out=noLights;
  21.         return;
  22.     }
  23.     unsigned long furtherLight=t-1;
  24.     bool even=(furtherLight%2==0);
  25.     furtherLight=min(furtherLight,I-1);
  26.     ostringstream oss("");
  27.     for (unsigned long i=(even?0:1);i<=furtherLight;i+=2)   {
  28.         oss<<i;
  29.         if (i+2<=furtherLight) oss<<' ';
  30.     }
  31.     if (oss.str().size()==0) out=noLights;
  32.     else out=oss.str();
  33. }
  34.  
  35. int main(int argc,char **argv)  {
  36.     //The first two lines are not strictly necessary, but make the code a little more handy.
  37.     if (argc>=2) freopen(argv[1],"r",stdin);
  38.     if (argc>=3) freopen(argv[2],"w",stdout);
  39.     string tmp;
  40.     unsigned int N,a,b;
  41.     getline(cin,tmp);
  42.     if (sscanf(tmp.c_str(),"%u",&N)!=1) return -1;
  43.     for (size_t i=0;i<N;++i)    {
  44.         do getline(cin,tmp); while (sscanf(tmp.c_str(),"%u",&a)!=1);
  45.         do getline(cin,tmp); while (sscanf(tmp.c_str(),"%u",&b)!=1);
  46.         solve(a,b,tmp);
  47.         cout<<tmp<<endl;
  48.     }
  49.     return 0;
  50. }
RAW Paste Data