I started to use map for a purely simulated question, but it has been wa for a long time.
There may be multiple spaces between names. At first, I searched from the left to the Right to overwrite the space position. But to the second space, I exited the loop and kept wa, switch to search from right to left, find the first one, and then exit. Then, it's over ............
I am wrong in the blank area of "A single blank space". This is a problem with English proficiency .................., I always thought it was a space.
View code
# Include <iostream>
# Include <algorithm>
Using Namespace STD;
Struct Name
{
Char STR [ 100 ];
Int K;
} NN [ 300 ];
Int Num, maxlen;
Int Findd ( Char * S)
{
For ( Int I = 0 ; I <num; I ++)
{
If (Strcmp (S, NN [I]. Str) = 0 )
{
NN [I]. K ++;
Return NN [I]. K;
}
}
Strcpy (NN [num]. STR, S );
NN [num ++]. k = 0 ;
Return 0 ;
}
Int Digit ( Int K)
{
Int S = K, t = 0 ;
While (S! =0 )
{
S/= 10 ;
T ++;
}
Return T;
}
Int Main ()
{
Int N, CAS = 0 ;
Char Ss [ 300 ], St [ 100 ];
While (Scanf ( " % D " , & N, & maxlen) = 2 & (N | maxlen ))
{
Getchar ();
Num = 0 ;
Printf ( " Case % d \ n " , ++ CAS );
For ( Int I =0 ; I <n; I ++)
{
Gets (SS );
Int Len = strlen (SS );
Int LAC = len- 1 ;
While (Ss [LAC]! = ' ' )
LAC --;
If (Isupper (ss [ 0 ])
St [ 0 ] = Ss [ 0 ] + 32 ;
Else St [ 0 ] = Ss [ 0 ];
Int Len1 = 1 ;
For ( Int J = LAC + 1 ; J <Len & len1 <maxlen; j ++)
{
If (Isupper (ss [J])
St [len1 ++] = ss [J] + 32 ;
Else If (Islower (ss [J])
St [len1 ++] = ss [J];
}
St [len1] = ' \ 0 ' ;
Int K = findd (ST );
If (K = 0 )
{
Puts (ST );
Continue ;
}
Int M = digit (K), Le = maxlen-len1;
If (Len1 + M <= maxlen)
{
Printf ( " % S % d \ n " , St, k );
Continue ;
}
St [len1-m + le] = ' \ 0 ' ;
Printf ( " % S % d \ n " , St, k );
}
}
Return 0 ;
}