-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1309 Decrypt String from Alphabet to Integer Mapping.c
More file actions
61 lines (52 loc) · 1.48 KB
/
1309 Decrypt String from Alphabet to Integer Mapping.c
File metadata and controls
61 lines (52 loc) · 1.48 KB
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
char hash_table[17] = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char * freqAlphabets(char * s)
{
int i=0;
int len = strlen(s);
char * ret_str = (char *)malloc(sizeof(char)*(len+1));
int ret_str_index = 0;
int start_index = 0;
if( (len == 0) || (len == 1) || (len == 2))
{
while(start_index < len)
{
ret_str[ret_str_index++] = (s[start_index] - '1' + 'a');
start_index++;
}
ret_str[ret_str_index] = '\0';
return ret_str;
}
int end_index = 2;
while((end_index < len) && (start_index < len))
{
if(s[end_index] == '#')
{
int num = 0;
num = (s[start_index] - '0')*10 + (s[start_index+1] - '0');
ret_str[ret_str_index++] = hash_table[num - 10];
start_index += 3;
end_index += 3;
}
else
{
ret_str[ret_str_index++] = (s[start_index] - '1' + 'a');
start_index++;
end_index++;
}
}
if((start_index>=len) && (end_index>=len))
{
ret_str[ret_str_index] = '\0';
}
else if((start_index<len) && (end_index >= len))
{
while(start_index < len)
{
ret_str[ret_str_index++] = (s[start_index] - '1' + 'a');
start_index++;
}
ret_str[ret_str_index] = '\0';
}
return ret_str;
}