PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Need
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need

Réponse
 
LinkBack Outils de la discussion
Vieux 21/02/2008, 09h31   #1
bigmoviebuff@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Need

Hi guys does any of you guys have this c++ program .
I need the program to input a string and accept a word number and
print this pattern.


Input) This is a message
Input)4

output) s
ssa
essag
message
essag
ssa
s

and if it is a even word for example golden then the output is


ld
olde
golden
olde
ld


Please can any of you guys write this program for me .
  Réponse avec citation
Vieux 21/02/2008, 12h31   #2
Zeppe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

bigmoviebuff@gmail.com wrote:

> Please can any of you guys write this program for me .


no.
  Réponse avec citation
Vieux 21/02/2008, 14h20   #3
Triple-DES
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

On 21 Feb, 10:31, bigmovieb...@gmail.com wrote:
> Hi guys does any of you guys have this c++ program .
> I need the program to input a string and accept a word number and
> print this pattern.
>
> Input) This is a message
> Input)4
>
> output) s
> ssa
> essag
> message
> essag
> ssa
> s
>
> and if it is a even word for example golden then the output is
>
> ld
> olde
> golden
> olde
> ld
>
> Please can any of you guys write this program for me .


Sure, here you go:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
ostream& o = cout;
istream& i = cin;
typedef string s;
typedef vector<s> v;
typedef s::iterator si;
typedef size_t t;
#define b_ begin()
#define e_ end()
int main() {
s s_; v v_; t n;
getline(i,s_);
i>>n;
while(--n) s_ = s(find(s_.b_, s_.e_,' ')+1,s_.e_);
s_ = s(s_.b_,find(s_.b_,s_.e_,' '));
t d = 0u;
t ll = s_.size();
for(t l = ((ll ^ 1u) & 1u) + 1; l <= ll {
si b = s_.b_ + (ll - l) / 2;
o<< s(b, b + l) << "\n";
l += 2 - d;
if(l >= ll) d = 4u;
}}
  Réponse avec citation
Vieux 21/02/2008, 14h55   #4
osmium
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

<bigmoviebuff@gmail.com> wrote:

> Hi guys does any of you guys have this c++ program .
> I need the program to input a string and accept a word number and
> print this pattern.
>
>
> Input) This is a message
> Input)4
>
> output) s
> ssa
> essag
> message
> essag
> ssa
> s
>
> and if it is a even word for example golden then the output is
>
>
> ld
> olde
> golden
> olde
> ld


There are two main parts to the question. Isolate a particular word and then
print that word in the funny pattern required. There are two kinds of
printing, depending on how many characters are in the word. Start by
writing a program that will get the two inputs from a user. isolate the
desired word and pass that word to a function *to be defined* (by you) that
will do the printing. For earrly testing, simply print the word in that
function.


  Réponse avec citation
Vieux 21/02/2008, 16h47   #5
red floyd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

bigmoviebuff@gmail.com wrote:
> Hi guys does any of you guys have this c++ program .
> I need the program to input a string and accept a word number and
> print this pattern.
>
> [redacted]


Hi bigmoviebuff, you can find your program here:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
  Réponse avec citation
Vieux 21/02/2008, 19h19   #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
Vieux 21/02/2008, 22h56   #7
jason.cipriani@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

On Feb 21, 2:19 pm, "P. Lepin" <le...@ranselett.net> wrote:
> Sure, why not.


I see; so that's the way you want to be. Fine.

*cracks knuckles*

#include <stdio.h>
int main(int Z,char*_,int N){switch(Z){case 0:if(*_){putchar(
main(Z-1,"double f;switch{}0x53*DEBUG=1+9.%|> !+./1256789:I_"
"abcdefghklmn""oprstuwy",*_));return main(Z,1+_,N);}return 0;
case -1:if(N==*_)return 36[_+Z] ;else return main(Z,_-Z,N);
}return main(Z-Z,"cd0D5{.5xd=GdU>dD=U5|=+Ed{.dD..1tll*+=%19b"
"*==*B5b0=Ul*+=%1l0=U1bB{G*b0uul}+=|95h3+Ul.D+5{xl 3xw;seif{w"
"3;f3 edo",N);}

That's C, mind you.

Jason
  Réponse avec citation
Vieux 22/02/2008, 03h12   #8
InsainFreak101@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

If your newer to c++, I would start with the word, then delete the the
end letters and display them above and below the original word until
the length of the string is 1 or 2.
  Réponse avec citation
Vieux 22/02/2008, 07h40   #9
Pavel Lepin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need


jason.cipriani@gmail.com <jason.cipriani@gmail.com> wrote in
<f71743fe-a37f-4cf1-96ba-045442e9c407@u69g2000hse.googlegroups.com>:
> On Feb 21, 2:19 pm, "P. Lepin" <le...@ranselett.net>
> wrote:
>> Sure, why not.

>
> I see; so that's the way you want to be. Fine.
>
> *cracks knuckles*
>
> #include <stdio.h>
> int main(int Z,char*_,int N){switch(Z){case
> 0:if(*_){putchar( main(Z-1,"double
> f;switch{}0x53*DEBUG=1+9.%|> !+./1256789:I_"
> "abcdefghklmn""oprstuwy",*_));return main(Z,1+_,N);}return
> 0;
> case -1:if(N==*_)return 36[_+Z] ;else return
> main(Z,_-Z,N); }return
> main(Z-Z,"cd0D5{.5xd=GdU>dD=U5|=+Ed{.dD..1tll*+=%19b"
> "*==*B5b0=Ul*+=%1l0=U1bB{G*b0uul}+=|95h3+Ul.D+

{xl3xw;seif{w"
> "3;f3 edo",N);}
>
> That's C, mind you.


Since we started switching languages, I could've whipped out
my Perl, and wouldn't THAT be horrible. But I won't. It's
off-topic here. :-)

(Translation: I'm chickening out!)

--
When all you have is a transformation engine, everything
looks like a tree.
  Réponse avec citation
Vieux 22/02/2008, 11h58   #10
Triple-DES
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

On 21 Feb, 20:19, "P. Lepin" <le...@ranselett.net> wrote:
> bigmovieb...@gmail.com wrote:
> > 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.


Good one! I really like how you involve so many c++ features in your
code. I don't think I can top this.
  Réponse avec citation
Vieux 22/02/2008, 12h26   #11
Pavel Lepin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need


Triple-DES <fire13all@hotmail.com> wrote in
<bcfe1c3d-06ab-49c1-b3fb-21f438d8e307@t66g2000hsf.googlegroups.com>:
> On 21 Feb, 20:19, "P. Lepin" <le...@ranselett.net> wrote:
>> bigmovieb...@gmail.com wrote:
>> > Please can any of you guys write this program for me .

>>
>> #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];}

>
> Good one!


Thank you for your kind words. :-)

> I really like how you involve so many c++ features in your
> code.


"Abuse", you mean. :-) Note how many template classes the
compiler instantiates. And how many std::strings are
instantiated at run-time (and never released). Catching
std:ut_of_range to stop recursion is pretty damn evil
too - I didn't even know I had it in me. I almost hope the
OP submits this to his instructor.

--
When all you have is a transformation engine, everything
looks like a tree.
  Réponse avec citation
Vieux 22/02/2008, 17h14   #12
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need

On Feb 21, 3:20 pm, Triple-DES <fire13...@hotmail.com> wrote:
> On 21 Feb, 10:31, bigmovieb...@gmail.com wrote:


[Obvious homework problem deleted...]

> Sure, here you go:


> #include <iostream>
> #include <string>
> #include <vector>
> #include <algorithm>
> using namespace std;
> ostream& o = cout;
> istream& i = cin;
> typedef string s;
> typedef vector<s> v;
> typedef s::iterator si;
> typedef size_t t;
> #define b_ begin()
> #define e_ end()
> int main() {
> s s_; v v_; t n;
> getline(i,s_);
> i>>n;
> while(--n) s_ = s(find(s_.b_, s_.e_,' ')+1,s_.e_);
> s_ = s(s_.b_,find(s_.b_,s_.e_,' '));
> t d = 0u;
> t ll = s_.size();
> for(t l = ((ll ^ 1u) & 1u) + 1; l <= ll {
> si b = s_.b_ + (ll - l) / 2;
> o<< s(b, b + l) << "\n";
> l += 2 - d;
> if(l >= ll) d = 4u;
> }}


Beautiful. It really pleases me to see that someone here has
finally learned how to respond to homework requests with some
originality.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h14.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,22595 seconds with 20 queries