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 <sstream>
- #include <iostream>
- using namespace std;
- string ns="No stops";
- 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,capacity,total,gs;
- unsigned int prev,next;
- unsigned int until;
- getline(cin,tmp);
- if (sscanf(tmp.c_str(),"%u",&N)!=1) return -1;
- for (size_t i=0;i<N;++i) {
- bool ws=false;
- int current;
- getline(cin,tmp);
- if (sscanf(tmp.c_str(),"%u",&capacity)!=1) return -1;
- getline(cin,tmp);
- if (sscanf(tmp.c_str(),"%u",&total)!=1) return -1;
- getline(cin,tmp);
- if (sscanf(tmp.c_str(),"%u",&gs)!=1) return -1;
- getline(cin,tmp);
- if (gs>1) { //Always, probably. But let's ensure it ;).
- istringstream iss(tmp);
- iss>>prev;
- until=capacity;
- for (size_t j=1;j<gs;++j) {
- iss>>next;
- if (iss.fail()) return -1;
- if (next>until) {
- if (ws) cout<<' ';
- cout<<prev;
- ws=true;
- until=capacity+prev;
- }
- prev=next;
- }
- if (until<total) {
- if (ws) cout<<' ';
- cout<<next;
- ws=true;
- }
- if (!ws) cout<<ns;
- cout<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement