예제 #1
0
int main(void)
{
    printf("%s\n", isIsomorphic("egg", "add") ? "TRUE" : "FALSE");
    printf("%s\n", isIsomorphic("foo", "bar") ? "TRUE" : "FALSE");
    printf("%s\n", isIsomorphic("title", "paper") ? "TRUE" : "FALSE");

    return 0;
}
bool isIsomorphic(node *r1, node *r2){
	if(r1 == NULL && r2 == NULL)
		return true;
	else if(r1 == NULL || r2 == NULL)
		return false;
	if(r1->data != r2->data)
		return false;
	return (isIsomorphic(r1->left, r2->left) && isIsomorphic(r1->right, r2->right)) || (isIsomorphic(r1->left, r2->right) && isIsomorphic(r1->right, r2->left));
}
int main(){
	// Let us create trees shown in above diagram
    struct node *n1 = newNode(1);
    n1->left        = newNode(2);
    n1->right       = newNode(3);
    n1->left->left  = newNode(4);
    n1->left->right = newNode(5);
    n1->right->left  = newNode(6);
    n1->left->right->left = newNode(7);
    n1->left->right->right = newNode(8);

    struct node *n2 = newNode(1);
    n2->left         = newNode(3);
    n2->right        = newNode(2);
    n2->right->left   = newNode(4);
    n2->right->right   = newNode(5);
    n2->left->right   = newNode(6);
    n2->right->right->left = newNode(8);
    n2->right->right->right = newNode(7);

    if (isIsomorphic(n1, n2))
       cout << "Yes";
    else
      cout << "No";
	return 0;
}
예제 #4
0
int main(int argc, char const *argv[])
{
	char *s = "qwertyuiop[]asdfghjkl;'\\zxcvbnm,./";
	char *t = "',.pyfgcrl/=aoeuidhtns-\\;qjkxbmwvz";

	printf("%d\n", isIsomorphic(t, s));
	return 0;
}
예제 #5
0
int main() {
	srand(time(NULL));

    string s, t;
    while(cin>>s>>t) {
        cout<<isIsomorphic(s, t)<<endl;
    }



    return 0;
}
예제 #6
0
int main() {
	string s, t;
	while (cin >> s >> t) {
		if (isIsomorphic(s, t)) {
			cout << "ok" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}
int main(){
    for(int i = 0; i < (n-1); i++){
        cin >> U >> V;
        U--;V--;
        addEdge(U,V);
    }
    for(int i = 0; i < (n-1); i++){
        cin >> U >> V;
        U--;V--;
        addEdge(n+U,n+V);
    }
    cout << (isIsomorphic() ? "S" : "N") << endl;
    return 0;
}
예제 #8
0
파일: main.cpp 프로젝트: chrzhang/abc
int main() {
    assert(isIsomorphic("egg", "add"));
    assert(!isIsomorphic("foo", "bar"));
    assert(isIsomorphic("paper", "title"));
    return 0;
}