-
Notifications
You must be signed in to change notification settings - Fork 1
/
Transform.c
73 lines (59 loc) · 1.19 KB
/
Transform.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
/*
* My machine will check if the encoding is correctly done or not
* User will provide input and output.
*
* Eg1:
* Input = hello
* Output = elloh
*
* Eg2:
* Input=listen
* Output=silent
*
* Like wise, make sure the output s exactly same from the input.My machine will encode.
*
*/
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define SLEN 100
#define NON_PRINT_CHAR 0x0D
int isTransformed (char *input, char *output);
int main()
{
char input[SLEN], output[SLEN];
printf ("\r Input: ");
scanf("%s", input);
printf ("\r Output: ");
scanf("%s", output);
printf ("\r %s\r\n", isTransformed (input, output)? "YES": "NO");
return 0;
}
/*
* checks if transformation is correct or not
* assume max string len is SLEN
* destroys input and output, so copy and pass
*/
int isTransformed (char *input, char *output)
{
int i, j;
for (i = 0; input[i] != '\0'; i++)
{
for (j = 0; output[j] != '\0'; j++)
{
if (input[i] == output[j])
{
input[i] = output[j] = NON_PRINT_CHAR;
break;
}
}
if (input[i] != NON_PRINT_CHAR)
return FALSE;
}
for (j = 0; output[j] != '\0'; j++)
{
if (output[j] != NON_PRINT_CHAR)
return FALSE;
}
return TRUE;
}