Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Array help! Find longest continuous sequence!!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
zengrz
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 33
Location: ca

PostPosted: Thu Feb 04, 2010 12:41 am    Post subject: Array help! Find longest continuous sequence!! Reply with quote

I have an array of 1s and 0s and I want to find the longest continuous sequence of 0s in the array. How do i do that? Thanks in advance.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Feb 04, 2010 2:58 am    Post subject: Reply with quote

i guess you can just iterate through with a counter ?
Back to top
View user's profile Send private message
Xenico
Advanced Cheater
Reputation: 0

Joined: 27 Dec 2009
Posts: 94

PostPosted: Thu Feb 04, 2010 10:17 am    Post subject: Reply with quote

make a loop until you find the first zero and then start another loop with a variable that counts the zeros. The second loop is stopped by the first 1. Then you will have a second var which gets the value of the first variable only if the first is greater than the second.
Got it? Smile

_________________
Back to top
View user's profile Send private message
zengrz
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 33
Location: ca

PostPosted: Fri Feb 05, 2010 12:42 am    Post subject: Reply with quote

i have an idea but my code doesnt work out. i thought that there is a more nifty way to do it. guess have to get back to debugging.
thank you guys for the help
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Feb 05, 2010 2:05 am    Post subject: Reply with quote

hurf

Code:
int main()
{
   char arr[15] = { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; //pulled out of my ass
   int i, ctr = 0, highest = 0;

   for(i = 0; i < 15; i++)
   {
      while(arr[i] == 0)   { ctr++; i++; }
      if(ctr > highest)
         highest = ctr;

      ctr   = 0;
   }

   return 0;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites