-
Notifications
You must be signed in to change notification settings - Fork 2
/
question1.c
73 lines (48 loc) · 840 Bytes
/
question1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1000
int hash1[256], hash2[256];
int cal(char *str1, char *str2){
int j;
for(j=0;j<256;j++){
hash1[j] = 0;
hash2[j] = 0;
}
int len1 =strlen(str1);
int len2 = strlen(str2);
if(len1 != len2){
return 0;
}
int i;
for(i=0;i<len1;i++){
if(hash1[str1[i]] == 0){
hash1[str1[i]] = str2[i];
}else{
if(hash1[str1[i]] != str2[i]){
return 0;
}
}
if(hash2[str2[i]] == 0){
hash2[str2[i]] = str1[i];
}else{
if(hash2[str2[i]] != str1[i]){
return 0;
}
}
}
return 1;
}
int main(){
int cases;
scanf("%d",&cases);
int i;
char str1[MAX], str2[MAX];
for(i=0;i<cases;i++){
scanf("%s",str1);
scanf("%s",str2);
int isIsomorphic = cal(str1, str2);
printf("%d\n",isIsomorphic);
}
return 0;
}