SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 05/05/2018, 06:06 PM   #1
DBZdabIt3Bro7
Little Clucker
 
Join Date: Sep 2017
Location: Lovely name, right?
Posts: 41
Reputation: 8
Default Looping an input to detect whether it's repetitive or not.

What's the best way to go through an input (string variable) to detect whether the content is repetitive or not?

For say;
PHP Code:
// repetitive inputs:
123123
123456
qwerty
jjjkkklll

//non-repetitive inputs:
194373
sdfkow
hello
good_bye
jlkjkl 


This is something I tried to do, however it doesn't work with such as: abc, but it does work with aaa; etc.

PHP Code:
#include <a_samp>

main() {
    new 
input[] = "abcd";

    new 
bool:repetitive false;

    for(new 
alpha 0alpha sizeof(input)-3alpha++) {
        if(
input[alpha] == input[alpha+1] && input[alpha] == input[alpha+2]) {
            
repetitive true;
            break;
        }

        if(
input[alpha+1] == input[alpha]+&& input[alpha+1] == input[alpha]+2) {
            
repetitive true;
            break;
        }
    }

    
printf("is repetitive: %i"repetitive);

    return 
1;

DBZdabIt3Bro7 is offline   Reply With Quote
Old 05/05/2018, 07:58 PM   #2
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,728
Reputation: 780
Default Re: Looping an input to detect whether it's repetitive or not.

So I spent some time and came up with this:
PHP Code:
func(string[]) {
    new 
len strlen(string);
    new 
bool:found;
    
    for (new 
0leni++) {
        
found false;
        
        for (new 
= (1); lenj++) {
            if (
string[j] == string[i]) {
                
strdel(stringj, (1));
                --
len;
                
                
found true;
            }
        }
        
        if (
found == true) {
            --
i;
        }
    }

__________________
Gammix is online now   Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping AnonScripter Scripting Help 6 07/10/2013 09:01 PM
looping from 4 to 8? newbienoob Scripting Help 6 17/08/2013 12:43 PM
Looping Sanady Scripting Help 4 30/04/2013 09:32 PM
Looping :/ Lorenc_ Help Archive 2 13/04/2011 10:16 AM
Repetitive server crash? ThePwherer Server Support 2 07/11/2010 03:25 PM


All times are GMT. The time now is 09:40 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.