1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sequence.cpp(c++11)

1
Last updated at Posted at 2013-05-19

c++11版です。
コンパイルオプション:mingw32-g++ -std=c++11 sequence.cpp
↑自分が忘れないためのメモ

# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <string>

int str2int( const char s )
{
    return ( s < 'a' ) ? s-'0': s-0x57;
}

void test( const std::string & input, const std::string & ans )
{
    int max_cnt = 1;
    for( const char c1: input )
    {
        for( const char c2: input.substr( input.find_first_of(c1)+1 ) )
        {
            const int diff = str2int(c2) - str2int(c1);
            char pre_c = c2;
            int cnt = 2;
            for( const char c3: input.substr( input.find_first_of(c2)+1 ) )
            {
                if( str2int(c3) == str2int(pre_c)+diff )
                {
                    cnt++;
                    pre_c = c3;
                }
                else if( str2int(c3) > str2int(pre_c)+diff )
                {
                    break;
                }
            }
            if( cnt > max_cnt ) max_cnt = cnt;
        }
    }
    printf("%s\n", (max_cnt == atoi(ans.c_str())) ? "ooooo GOOD ooooo": "xxxxx BAD xxxxx");
}

int main( void )
{
/*0*/ test( "12345abcz", "5" );
/*1*/ test( "012abku", "4" );
/*2*/ test( "01245689cdeghik", "6" );
/*3*/ test( "0", "1" );
/*4*/ test( "m", "1" );
/*5*/ test( "01", "2" );
/*6*/ test( "az", "2" );
/*7*/ test( "0az", "2" );
/*8*/ test( "0ak", "3" );
/*9*/ test( "05ak", "3" );
/*10*/ test( "01349acdrsuv", "2" );
/*11*/ test( "01245789efgipqstux", "3" );
/*12*/ test( "0123456789abcdefghijklmnopqrstuvwxyz", "36" );
/*13*/ test( "02468acegikmoqsuwy", "18" );
/*14*/ test( "0369cfilorux", "12" );
/*15*/ test( "048cgkosw", "9" );
/*16*/ test( "05afkpuz", "8" );
/*17*/ test( "0123456789abcdefghjklmnopqrstuvwxyz", "18" );
/*18*/ test( "0123456789bcdefghijklmopqrstuvwxyz", "12" );
/*19*/ test( "0156abfgklpquv", "7" );
/*20*/ test( "0167cdijopuv", "6" );
/*21*/ test( "0178eflmst", "5" );
/*22*/ test( "0189ghopwx", "5" );
/*23*/ test( "019aijrs", "4" );
/*24*/ test( "012567abcfghklmpqruvw", "7" );
/*25*/ test( "012678cdeijkopquvw", "6" );
/*26*/ test( "012789efglmnstu", "5" );
/*27*/ test( "01289aghiopqwxy", "5" );
/*28*/ test( "0129abijkrst", "4" );
/*29*/ test( "01235678abcdfghiklmnpqrsuvwx", "7" );
/*30*/ test( "01236789cdefijklopqruvwx", "12" );
/*31*/ test( "0123789aefghlmnostuv", "5" );
/*32*/ test( "012389abghijopqrwxyz", "5" );
/*33*/ test( "01239abcijklrstu", "4" );
/*34*/ test( "368acdknouvz", "4" );
/*35*/ test( "369chikmnopqruwx", "6" );
/*36*/ test( "05689cdefghijklmnopqrstvwy", "18" );
/*37*/ test( "2489abdeiklrsuvwz", "4" );
/*38*/ test( "678bhijklnpqrsuvwxyz", "6" );
/*39*/ test( "1246cfjkopquxz", "5" );
/*40*/ test( "123459abcefhilmotuvx", "6" );
/*41*/ test( "02578acdefikmopqsuvwxz", "8" );
/*42*/ test( "135abdefghijlopstuwz", "7" );
/*43*/ test( "0126789fgjnotuvxy", "5" );
/*44*/ test( "2345678defjkmnoqrtvwxy", "7" );
/*45*/ test( "02568bdemnostw", "5" );
/*46*/ test( "145689bdfhilnqrstvwxz", "6" );
/*47*/ test( "4aghjrtuvwxyz", "7" );
/*48*/ test( "158achklmqstwy", "3" );
/*49*/ test( "012346abceghjknortv", "5" );
    return 0;
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?