C,233字节
#include <stdlib.h>
#include <string.h>
#define h char
#define r return
int c(void*a,void*b){r*(h*)a-*(h*)b;}int a(h*s,h*t){int l=strlen(s),m=strlen(t);if(l!=m)r 0;qsort(s,l,1,c);qsort(t,m,1,c);while(l--)if(abs(s[l]-t[l])>1)r 0;r 1;}
您可以通过将其另存为adj.h
然后使用以下adj.c
文件来对其进行测试:
#include <stdio.h>
#include "adj.h"
int main() {
char aa[] = "A", A[] = "A";
char b[] = "A", B[] = "B";
char cc[] = "C", C[] = "B";
char d[] = "DD", D[] = "CE";
char e[] = "DE", E[] = "FC";
char f[] = "ABCD", F[] = "BCDE";
char g[] = "AACC", G[] = "DBBB";
char hh[] = "DJENSKE", H[] = "FDJCLMT";
char i[] = "DEFGHIJKL", I[] = "HJLEHMCHE";
char j[] = "IKLIJJLIJKKL", J[] = "LJLJLJLJLJHI";
char k[] = "ACEGIKMOQSUWY", K[] = "BLNPRDFTVHXJZ";
char l[] = "QQSQQRRQSTTUQQRRRS", L[] = "PQTTPPTTQTPQPPQRTP";
char m[] = "ELKNSDUUUELSKJFESD", M[] = "DKJELKNSUELSDUFEUS";
char n[] = "A", N[] = "C";
char o[] = "A", O[] = "Z";
char p[] = "B", P[] = "J";
char q[] = "JK", Q[] = "J";
char rr[] = "CC", R[] = "BA";
char s[] = "CE", S[] = "D";
char t[] = "DJENSKE", T[] = "GDJCLMT";
char u[] = "DEFGHIJKL", U[] = "HJLHMCHE";
char v[] = "IJKLIJKLKIJL", V[] = "LIJLLHJLJLLL";
char w[] = "AWSUKMEGICOQY", W[] = "RSHXBLJLNQDFZ";
char x[] = "QQSQQRRQSTTUQQQRRS", X[] = "PQTTPPTTQTPQPPQRTT";
char y[] = "ELKNSDUVWELSKJFESD", Y[] = "DKJELKNSUELSDUFEUS";
char *z[] = {aa,b,cc,d,e,f,g,hh,i,j,k,l,m,n,o,p,q,rr,s,t,u,v,w,x,y};
char *Z[] = {A ,B,C ,D,E,F,G,H ,I,J,K,L,M,N,O,P,Q,R ,S,T,U,V,W,X,Y};
for(int _=0;_<25;_++) {
printf("%s %s: %s\r\n", z[_], Z[_], a(z[_], Z[_]) ? "true" : "false");
}
return 0;
}
然后使用编译gcc adj.c -o adj
。输出为:
A A: true
A B: true
C B: true
DD CE: true
DE CF: true
ABCD BCDE: true
AACC BBBD: true
DEEJKNS CDFJLMT: true
DEFGHIJKL CEEHHHJLM: true
IIIJJJKKKLLL HIJJJJJLLLLL: true
ACEGIKMOQSUWY BDFHJLNPRTVXZ: true
QQQQQQQRRRRRSSSTTU PPPPPPPQQQQRTTTTTT: true
DDEEEFJKKLLNSSSUUU DDEEEFJKKLLNSSSUUU: true
A C: false
A Z: false
B J: false
JK J: false
CC AB: false
CE D: false
DEEJKNS CDGJLMT: false
DEFGHIJKL HJLHMCHE: false
IIIJJJKKKLLL HIJJJLLLLLLL: false
ACEGIKMOQSUWY BDFHJLLNQRSXZ: false
QQQQQQQQRRRRSSSTTU PPPPPPQQQQRTTTTTTT: false
DDEEEFJKKLLNSSSUVW DDEEEFJKKLLNSSSUUU: false
"A A"
吗?