if you could just type thee right code into a reply that would be great
Thx a lot
![:smile:](./images/smilies/icon_smile.gif)
Moderator: Board moderators
Code: Select all
int i;
while (scanf("%*[ t]"), ungetc(fgetc(stdin),stdin)!=EOF) {
while (scanf("%*[ t]"), ungetc(fgetc(stdin),stdin)!='n') {
scanf("%d",&i);
printf("%d-",i);
}
fgetc(stdin);
printf("EOLn");
}
Code: Select all
#pragma warning (disable : 4786)
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
void Tokenize(const string& S,vector<string>& T,const string& D = " ")
{
string::size_type LP,P;
LP=S.find_first_not_of(D);
P=S.find_first_of(D, LP);
while (string::npos!=P||string::npos!=LP)
{
T.push_back(S.substr(LP,P-LP));
LP = S.find_first_not_of(D, P);
P = S.find_first_of(D, LP);
}
}
vector<string> gLine(vector<string>&T)
{
char B[1000];
T.clear();
if(gets(B)!=NULL)
Tokenize(B,T);
return T;
}
void Flip(vector<int> &X, int T)
{
reverse(&X[0],&X[X.size()-T+1]);
}
void main()
{
vector<string> T;
vector<int> X,S;
int i;
vector<int>::iterator I,J;
while(gLine(T).size()>0)
{
X.clear();
for(i=0;i<T.size();i++)
{
X.push_back(strtol(T[i].c_str(),NULL,10));
}
S=X;
stable_sort(S.begin(),S.end());
for(I=S.end()-1;I>=S.begin();I--)
{
J=find(X.begin(),X.end(),*I);
if(X.end()-J!=S.end()-I)
{
if(J!=X.begin())
{
printf("%d ",X.end()-J);
Flip(X,X.end()-J);
}
printf("%d ",S.end()-I);
Flip(X,S.end()-I);
}
}
printf("0n");
}
}