Discussion: Need help
Afficher un message
Vieux 21/02/2008, 20h19   #6
P. Lepin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need


bigmoviebuff@gmail.com wrote:
> I need the program to input a string and accept a word number and
> print this pattern.
>
> output) s
> ssa
> essag
> message
> essag
> ssa
> s
>
> Please can any of you guys write this program for me .


Sure, why not.

#include <stdexcept>
#include <string>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
using namespace std;
#define m 1<<8
#define si signed int
#define sz size
#define sb substr
#define st string
#define ss istringstream
#define cc(y) c<t,(l-y>0?l-y:1)>
template<class t,si l> class c{
public:t s_,z_;cc(2)*t_;si b_,l_;
static t*p(t s){t x;x=l==1?s:*cc(1)::p(s);
return new t(t(x.sz()<l?" ":"")+x);}
c(t s,si n=0)
:s_(s),z_(*c<t,m>::p(s)),b_(1),l_(!n?s.sz():n){
try{t_=new cc(2)(s_.sb(1,s_.sz()-2),l_);}
catch(out_of_range e){b_=!b_;}}
virtual ~c(){if(b_)delete t_;}
void operator[](si x){(*this)(x);if(b_)(*t_)[!b_];}
void operator()(si x){if(b_&&x)(*t_)(x);
if(l_!=l)cout<<z_.sb(z_.sz()-l_)<<endl;}};
int main(){st g,w;getline(cin,g);si i;cin>>i;ss k(g);
while(i--){k>>w;}c<st,m>o(w);o[1];}

There you go.

--
"These men died for us... frequently!"
  Réponse avec citation
 
Page generated in 0,04913 seconds with 9 queries