problem 2828

      没有什么花头,跟之前做的一道题几乎是用同样的解法。(详见Language of FatMouse

  
Accepted
C
00:00.00
404K
#include<stdio.h>
#include<string
.h>
#include
<stdlib.h>
#define swap(a,b) {a = a ^ b; b = b ^ a; a = a ^ b;}
char dic[101][21 ];
int cmp(const void* a,const void*
 b)
{
    
return strcmp((char*)a,(char*
)b);
}
void
 solve()
{
    
int cnt1,cnt2,cnt3 = 0
,i,j;
    
char w[21],res[101][21
];
    scanf(
"%d",&
cnt1);
    
for(i = 0; i < cnt1; i++
)
        scanf(
"%s",&
dic[i]);
    qsort(dic,cnt1,
sizeof(dic[0
]),cmp);
    scanf(
"%d",&
cnt2);
    
for(i = 0; i < cnt2; i++
)
    {
        scanf(
"%s",&
w);
        
int len =
 strlen(w);
        
char *= (char*)bsearch(w,dic,cnt1,sizeof(dic[0
]),cmp);
        
if(t !=
 NULL)
        {
            puts(w);
            
continue
;
        }
        cnt3 
= 0
;
        
for(j = 0; j < len - 1; j++
)
        {
            swap(w[j],w[j 
+ 1
]);
            t 
= (char*)bsearch(w,dic,cnt1,sizeof(dic[0
]),cmp);
            
if(t !=
 NULL)
                strcpy(res[cnt3
++
],t);
            swap(w[j],w[j 
+ 1
]);
        }
        
if(cnt3 == 0
)
            puts(w);
        
else

        {
            qsort(res,cnt3,
sizeof(res[0 ]),cmp);
            
for(j = 0; j < cnt3; j++
)
                j 
!= 0 ? printf(",%s",res[j]) : printf("%s"
,res[j]);
            putchar(
10
);
        }
    }
}
void
 main()
{
    
int
 t;
#ifndef ONLINE_JUDGE
    freopen(
"test.txt","r",stdin);
#endif
    
while(scanf("%d",&t) !=  EOF)
        
while(t--
)
        {
            solve();
            
if(t != 0
)
                putchar(
10
);
        }
#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值