-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisUnique.c
49 lines (39 loc) · 906 Bytes
/
isUnique.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
#include <stdio.h>
#include <string.h>
#include <time.h>
#define MAX_ASCII_TABLE 256
#define MAX_UTF8_TABLE 192
#define FALSE 0
#define TRUE 1
#define MAX_CHARS MAX_ASCII_TABLE
#define INPUT "ABCDEFGHIJKLMNOPQRSTUVXZ"
int isUnique(char *input);
int main()
{
char initialTime = time(NULL);
if (isUnique(INPUT))
printf("TRUE\n");
else
printf("FALSE\n");
printf("The total run time was %d seconds", (int)(initialTime - time(NULL)));
return 0;
}
int isUnique(char *input)
{
size_t lenght = strlen(input);
char head, test;
// Ad Hoc Jumps
if (lenght < 2)
return TRUE;
if (lenght > MAX_CHARS)
return FALSE;
for (head = 0; head < lenght - 1; head++)
{
for (test = head + 1; test < lenght; test++)
{
if (input[head] == input[test])
return FALSE;
}
}
return TRUE;
}