For this question, your program is required to process an input string containing only ASCII characters between ‘0’ and ‘9’, or between ‘a’ and ‘z’ (including ‘0’, ‘9’, ‘a’, ‘z’).
1. Characters in each segment should be in strictly increasing order. For ordering, ‘9’ is larger than ‘0’, ‘a’ is larger than ‘9’, and ‘z’ is larger than ‘a’ (basically following ASCII character order).
2. Characters in the second segment must be the same as or a subset of the first segment; and every following segment must be the same as or a subset of its previous segment.
aabbccdd
007799aabbccddeeff113355zz
1234.89898
abcdefabcdefabcdefaaaaaaaaaaaaaabbbbbbbddddddee樣例輸出
abcdabcd
013579abcdefz013579abcdefz
<invalid input string>
abcdefabcdefabcdefabdeabdeabdabdabdabdabaaaaaaa
#include<stdio.h>
#include<string.h>
void paixu(char input[],int len,int hashkey[])
{
int i,j,temp;
for(i=0;i<36;i++)
{
hashkey[i]=0;
}
for(i=0;i<len;i++)
{
if( (input[i]>='0' && input[i]<='9') )
{
temp = input[i] - '0';
hashkey[temp]++;
}
else if( input[i]>='a' && input[i]<='z')
{
temp = input[i] - 'a' + 10;
hashkey[temp]++;
}
else
{
printf("<invalid input string>\n") ;
return ;
}
}
i=0;
while(i<len)
{
j=0;
while(i<len && j<36)
{
if( hashkey[j] != 0 )
{
hashkey[j]--;
if(j<10)
{
input[i++]=j+'0';
}
else
{
input[i++]= j - 10 +'a';
}
}
j++;
}
}
input[i]='\0';
puts(input) ;
}
int main()
{
int hash_key[36];
char inp[1024];
int i;
int temp;
while(1)
{
gets(inp);
int len =strlen(inp);
paixu(inp, len,hash_key);
}
}