没睡醒呢,排个序排了老半天,还是调qsort排的(懒啊~~)。
Accepted | 1225 | C++ | 00:00.01 | 432K |
自己写个快排可以更快些的。
#include<stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define sz(a) (8 * sizeof(a))
int cmp1(const void* a,const void* b)
{
return *(int*)a - *(int* )b;
}
int cmp2(const void* a,const void* b)
{
char a1[20] = "",b1[20] = "" ;
int i;
strcpy(a1,(char* )a);
strcpy(b1,(char* )b);
for(i = 0; a1[i]; i++ )
a1[i] = tolower(a1[i]);
for(i = 0; b1[i]; i++ )
b1[i] = tolower(b1[i]);
return strcmp(a1,b1);
}
void solve(char s[])
{
char str[100][20 ];
int num[100],i,p = 0,q = 0,len,cnt = 0,flag[20 ];
memset(flag,0,sizeof (flag));
do
{
len = strlen(s);
if(isalpha(s[0]) == 0 )
{
num[q++] = atoi(s);
flag[cnt / sz(int)] |= (1 << (sz(int) - cnt % sz(int) - 1 ));
}
else
{
strcpy(str[p],s);
str[p][len - 1] = 0 ;
p++ ;
}
cnt++ ;
}while(s[len - 1] != '.' && scanf("%s",s) != EOF);
if(q > 1) qsort(num,q,sizeof(num[0 ]),cmp1);
if(p > 1) qsort(str,p,20 * sizeof(char ),cmp2);
for(i = p = q = 0; i < cnt; i++ )
{
int temp = flag[i / sz(int)] & (1 << (sz(int) - i % sz(int) - 1 ));
if(temp != 0) printf("%d",num[q++ ]);
else printf("%s",str[p++ ]);
if(i < cnt - 1) printf(", " );
}
printf("./n" );
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1225.txt","r" ,stdin);
#endif
char str[20 ];
while(scanf("%s",str) != EOF && str[0] != '.' )
solve(str);
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0 ;
}
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define sz(a) (8 * sizeof(a))
int cmp1(const void* a,const void* b)
{
return *(int*)a - *(int* )b;
}
int cmp2(const void* a,const void* b)
{
char a1[20] = "",b1[20] = "" ;
int i;
strcpy(a1,(char* )a);
strcpy(b1,(char* )b);
for(i = 0; a1[i]; i++ )
a1[i] = tolower(a1[i]);
for(i = 0; b1[i]; i++ )
b1[i] = tolower(b1[i]);
return strcmp(a1,b1);
}
void solve(char s[])
{
char str[100][20 ];
int num[100],i,p = 0,q = 0,len,cnt = 0,flag[20 ];
memset(flag,0,sizeof (flag));
do
{
len = strlen(s);
if(isalpha(s[0]) == 0 )
{
num[q++] = atoi(s);
flag[cnt / sz(int)] |= (1 << (sz(int) - cnt % sz(int) - 1 ));
}
else
{
strcpy(str[p],s);
str[p][len - 1] = 0 ;
p++ ;
}
cnt++ ;
}while(s[len - 1] != '.' && scanf("%s",s) != EOF);
if(q > 1) qsort(num,q,sizeof(num[0 ]),cmp1);
if(p > 1) qsort(str,p,20 * sizeof(char ),cmp2);
for(i = p = q = 0; i < cnt; i++ )
{
int temp = flag[i / sz(int)] & (1 << (sz(int) - i % sz(int) - 1 ));
if(temp != 0) printf("%d",num[q++ ]);
else printf("%s",str[p++ ]);
if(i < cnt - 1) printf(", " );
}
printf("./n" );
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1225.txt","r" ,stdin);
#endif
char str[20 ];
while(scanf("%s",str) != EOF && str[0] != '.' )
solve(str);
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0 ;
}