Question: enter a bunch of numbers to check the minimum number of ascending substrings (non-consecutive substrings) in a pile of numbers. One number is also considered a single substrings.
[Cpp] # include <iostream>
# Include <stdio. h>
# Include <string. h>
Using namespace std;
Const int n= 7003;
Int ELFhash (char * key)
{
Unsigned long h = 0;
Unsigned long g;
While (* key)
{
H = (h <4) + * key ++;
G = h & 0xf0000000LL;
If (g) h ^ = g> 24;
H & = ~ G;
}
Return h;
}
Int hash [N], count [N];
Int maxval, n;
Void hashhit (char * str)
{
Int k, t;
While (* str = '0') str ++;
K = ELFhash (str );
T = k % N;
While (hash [t]! = K & hash [t]! =-1)
T = (t + 10) % N;
If (hash [t] =-1) count [t] = 1, hash [t] = k;
Else if (++ count [t]> maxval) maxval = count [t];
}
Int main ()
{
Char str [105];
While (cin> n)
{
Memset (hash,-1, sizeof (hash ));
Maxval = 1;
While (n --)
{
Cin> str;
Hashhit (str );
}
Cout <maxval <endl;
}
Return 0;
}
# Include <iostream>
# Include <stdio. h>
# Include <string. h>
Using namespace std;
Const int n= 7003;
Int ELFhash (char * key)
{
Unsigned long h = 0;
Unsigned long g;
While (* key)
{
H = (h <4) + * key ++;
G = h & 0xf0000000LL;
If (g) h ^ = g> 24;
H & = ~ G;
}
Return h;
}
Int hash [N], count [N];
Int maxval, n;
Void hashhit (char * str)
{
Int k, t;
While (* str = '0') str ++;
K = ELFhash (str );
T = k % N;
While (hash [t]! = K & hash [t]! =-1)
T = (t + 10) % N;
If (hash [t] =-1) count [t] = 1, hash [t] = k;
Else if (++ count [t]> maxval) maxval = count [t];
}
Int main ()
{
Char str [105];
While (cin> n)
{
Memset (hash,-1, sizeof (hash ));
Maxval = 1;
While (n --)
{
Cin> str;
Hashhit (str );
}
Cout <maxval <endl;
}
Return 0;
}