Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Pablo Moreno Olalla
- Email address: darthbrevu@yahoo.es
- */
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- //This is an extremely simple problem!!
- string noLights="All lights are off :(";
- void solve(unsigned long I,unsigned long t,string &out) {
- if (t==0) {
- out=noLights;
- return;
- }
- unsigned long furtherLight=t-1;
- bool even=(furtherLight%2==0);
- furtherLight=min(furtherLight,I-1);
- ostringstream oss("");
- for (unsigned long i=(even?0:1);i<=furtherLight;i+=2) {
- oss<<i;
- if (i+2<=furtherLight) oss<<' ';
- }
- if (oss.str().size()==0) out=noLights;
- else out=oss.str();
- }
- int main(int argc,char **argv) {
- //The first two lines are not strictly necessary, but make the code a little more handy.
- if (argc>=2) freopen(argv[1],"r",stdin);
- if (argc>=3) freopen(argv[2],"w",stdout);
- string tmp;
- unsigned int N,a,b;
- getline(cin,tmp);
- if (sscanf(tmp.c_str(),"%u",&N)!=1) return -1;
- for (size_t i=0;i<N;++i) {
- do getline(cin,tmp); while (sscanf(tmp.c_str(),"%u",&a)!=1);
- do getline(cin,tmp); while (sscanf(tmp.c_str(),"%u",&b)!=1);
- solve(a,b,tmp);
- cout<<tmp<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement