zoj 2828 Auto Spell Corrector

zoj 2828 Auto Spell Corrector,第1张

zoj 2828 Auto Spell Corrector
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<string>using namespace std;char a[105][100];int n,m,k;int f[105],fs;char c[100];int pan(){int i;for(i=1;i<=m;i++){if(!strcmp(a[i],c)){f[fs]=i;fs++;return 1;}}return 0;}int fun(){int i,l;l=strlen(c);if(pan())return 1;for(i=1;i<l;i++){c[i-1]=c[i-1]^c[i];c[i]=c[i-1]^c[i];c[i-1]=c[i-1]^c[i];pan();c[i-1]=c[i-1]^c[i];c[i]=c[i-1]^c[i];c[i-1]=c[i-1]^c[i];}return 0;}bool cmp(int x,int y){if(strcmp(a[x],a[y])<0)return 1;elsereturn 0;}int main(){int i,t=0;while(scanf("%d",&n)!=EOF){while(n--){if(t==0)t=1;elseprintf("n");scanf("%d",&m);for(i=1;i<=m;i++)scanf("%s",a[i]);scanf("%d",&k);while(k--){fs=0;scanf("%s",c);if(fun()){printf("%s",a[f[0]]);}else if(fs!=0){sort(f,f+fs,cmp);for(i=0;i<fs;i++){if(i!=0)printf(",");printf("%s",a[f[i]]);}}else{printf("%s",c);}printf("n");}}}}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4912897.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存