GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Nov-2003, 16:01
rjd72285 rjd72285 is offline
New Member
 
Join Date: Oct 2003
Posts: 5
rjd72285 is an unknown quantity at this point

Please Help! Very Lost!


Hi I need to write a program and I am very lost if someone could help that would be very very appreciated. Here's my situation.

I need to generate a set of random letters(which I kind of have). Using these random letters, I have to find the word "hydrogen" if it is even created. I also need to find out what index value it started at. If the word hydrogen did not appear in the list of letters, i need to print out the part of the word that did.
For example, if the pile of random letters generated was:
jklsfhfkhyfashydrojksadfjdfldf
then I need to show that from the word hydrogen, the longest part of it created was hydro and it started at index value 13.
I need to use a vector or list, since it has to run for a few hours to find the word. if you can help with that, thanks.

here is my code for getting the random letters.
CPP / C++ / C Code:
#include<iostream>
#include<ctime>
#include<iomanip>
#include<cstdlib>

using namespace std;

int main()
{
	clock_t end;
	double counta = 0, countb = 0, countc = 0, countd = 0, counte = 0, countf = 0, countg = 0, counth = 0, counti = 0;
	double countj = 0, countk = 0, countl = 0, countm = 0, countn = 0, counto = 0, countp = 0, countq = 0, countr = 0;
	double counts = 0, countt = 0, countu = 0, countv = 0, countw = 0, countx = 0, county = 0, countz = 0, count = 0;
	double total = 0;
	srand(time(0));
	end = clock() + 1 * CLK_TCK;
	
	while(clock() < end)
	{
		int letter = rand()%27;
	
	switch(letter){
	
	case 1:	cout<<"a";	++counta;	break;
	case 2:	cout<<"b";	++countb;	break;
	case 3:	cout<<"c";	++countc;	break;
	case 4:	cout<<"d";	++countd;	break;
	case 5:	cout<<"e";	++counte;	break;
	case 6:	cout<<"f";	++countf;	break;
	case 7:	cout<<"g";	++countg;	break;
	case 8:	cout<<"h";	++counth;	break;
	case 9:	cout<<"i";	++counti;	break;
	case 10:cout<<"j";	++countj;	break;
	case 11:cout<<"k";	++countk;	break;
	case 12:cout<<"l";	++countl;	break;
	case 13:cout<<"m";	++countm;	break;
	case 14:cout<<"n";	++countn;	break;
	case 15:cout<<"o";	++counto;	break;
	case 16:cout<<"p";	++countp;	break;
	case 17:cout<<"q";	++countq;	break; 
	case 18:cout<<"r";	++countr;	break;
	case 19:cout<<"s";	++counts;	break;
	case 20:cout<<"t";	++countt;	break;
	case 21:cout<<"u";	++countu;	break;
	case 22:cout<<"v";	++countv;	break;
	case 23:cout<<"w";	++countw;	break;
	case 24:cout<<"x";	++countx;	break;
	case 25:cout<<"y";	++county;	break;
	case 26:cout<<"z";	++countz;	break;
	default:cout<<" ";	++count;	break;
	}
	
	}
	total = count + counta + countb + countc + countd + counte + countf + countg + counth + counti + countj + countk + countl + countm + countn + counto + countp + countq + countr + counts + countt + countu + countv + countw + countx + county + countz;
	cout<<endl;
	cout<<"Number of A's: "<<counta<<endl<<"Number of B's: "<<countb<<endl<<"Number of C's: "<<countc<<endl;
	cout<<"Number of D's: "<<countd<<endl<<"Number of E's: "<<counte<<endl<<"Number of F's: "<<countf<<endl;
	cout<<"Number of G's: "<<countg<<endl<<"Number of H's: "<<counth<<endl<<"Number of I's: "<<counti<<endl;
	cout<<"Number of J's: "<<countj<<endl<<"Number of K's: "<<countk<<endl<<"Number of L's: "<<countl<<endl;
	cout<<"Number of M's: "<<countm<<endl<<"Number of N's: "<<countn<<endl<<"Number of O's: "<<counto<<endl;
	cout<<"Number of P's: "<<countp<<endl<<"Number of Q's: "<<countq<<endl<<"Number of R's: "<<countr<<endl;
	cout<<"Number of S's: "<<counts<<endl<<"Number of T's: "<<countt<<endl<<"Number of U's: "<<countu<<endl;
	cout<<"Number of V's: "<<countv<<endl<<"Number of W's: "<<countw<<endl<<"Number of X's: "<<countx<<endl;
	cout<<"Number of Y's: "<<county<<endl<<"Number of Z's: "<<countz<<endl<<"Number of spacess: "<<count<<endl;
	cout<<setprecision(10)<<"Total Characters: "<<total<<endl;
	return 0;
}

if someone can tell me of an easier way to convert numbers to letters that would also be very helpful. I know you need to use static_cast but not sure how.
Another note for my code. I am measuring it by time, so after 2 seconds it stops. But it is not very accurate, if someone can help me with that too, it would be great.

ANY HELP IS GREATLY GREATLY APPRECIATED.
if you need me to further explain something, just respond saying so. If you can e-mail with help would also be great. rjd72285@yahoo.com
Thanks.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:03.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.