-
Notifications
You must be signed in to change notification settings - Fork 0
/
split32.c
84 lines (73 loc) · 1.88 KB
/
split32.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
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (C) 2014 Tomasz Kramkowski <[email protected]>
*
* This program is free software. It is licensed under version 3 of the
* GNU General Public License.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [http://www.gnu.org/licenses/].
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
char *nodup(char *, int *);
char *nnodup(char *, int *);
char *dup(char *, int *);
int main(int argc, char **argv)
{
int i;
if(argc!=2)
exit(1);
char *string = *(argv+1);
int dict[26];
memset(dict, 0, 26*sizeof(int));
for(i = 0; i < strlen(string); i++)
string[i] = toupper(string[i]);
printf("nodup: %s\n", nodup(string, dict));
printf("nnodup: %s\n", nnodup(string, dict));
printf("dup: %s\n", dup(string, dict));
int ii;
for(i=0; i<26; i++){
putchar('A'+i);
for(ii=0; ii<dict[i]; ii++)
putchar('=');
putchar('\n');
}
return 0;
}
char *nodup(char *input, int *dict)
{
char *output = malloc(strlen(input)+1);
int i, outpt = 0;
for(i=0; i<strlen(input); i++){
if(!dict[input[i]-'A']){
output[outpt++]=input[i];
}
dict[input[i]-'A'] += 1;
}
output[outpt]='\0';
return output;
}
char *nnodup(char *input, int *dict)
{
char *output = malloc(strlen(input)+1);
int i, outpt = 0;
for(i=0; i<strlen(input); i++)
if(dict[input[i]-'A']==1)
output[outpt++]=input[i];
output[outpt]='\0';
return output;
}
char *dup(char *input, int *dict)
{
char *output = malloc(strlen(input)+1);
int i, outpt = 0;
for(i=0; i<strlen(input); i++)
if(dict[input[i]-'A']>1)
output[outpt++]=input[i];
output[outpt] = '\0';
int ndict[26];
memset(ndict, 0, 26*sizeof(int));
return nodup(output, ndict);
}