私は大学で C コースを行っていますが、次のコード (再帰) を取得できないため、まだ Java に固執していると思います。
#include <stdio.h>
#include <conio.h>
#define N 11
int Combination(char *, char *, char *);
void main(){
int i;
char *S1[]={"","abc","abc","abc","abc","ab c","morning Venm","ABZ","12189","12189",
"TTTT"},
*S2[]={"", "", "def", "def", "def", "def", "Good ita!", "ABAXZ", "129", "129",
"X"},
*S3[]={"", "abc", "abcdef", "daebcf", "adfbce", "deab cf","Good morning Vietnam!",
"ABAXABZZ", "12181299", "12112998", "XXXXX"};
for(i=0;i<N;i++){
if(Combination(S1[i],S2[i],S3[i]))
printf("S1: \"%s\", S2: \"%s\", S3: \"%s\",
Combination!\n",S1[i],S2[i],S3[i]);
else printf("S1: \"%s\", S2: \"%s\", S3: \"%s\", Not a
Combination!\n",S1[i],S2[i],S3[i]);
}
_getch();
}
/*Function name : Combination
Input : address of three strings
Output : true(1) if the third string is a combination of the two firsts strings,
false (0) if not
Algorithm : check if the third string is made from the letters of the first and
second strings*/
int Combination(char *S1, char *S2, char *S3)
{
if(!*S1 && !*S2 && !*S3) return 1;
if(*S3==*S1 && *S3==*S2)
return (Combination(S1+1,S2,S3+1)||Combination(S1,S2+1,S3+1));
if(*S3==*S1) return Combination(S1+1,S2,S3+1);
if(*S3==*S2) return Combination(S1,S2+1,S3+1);
return 0;
}
Combination メソッドの任意の行を理解したい。
1) if(!*S1 && !*S2 && !*S3) = 3 つの文字列が null かどうかを確認しますか?
2) (S1+1,S2,S3+1) のどの部分ですか? S1+1 は、配列の次の単語または次の文字 ? を返します。それが次の手紙を私たちに与えるなら - 何のために?文字列が等しいかどうかはすでにチェックされていますか?
よくわかりません...
- 再帰を取得しましたが、S1+1\S2+1\S3+1 の部分ではありません...