-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10789.cpp
More file actions
80 lines (60 loc) · 1.28 KB
/
10789.cpp
File metadata and controls
80 lines (60 loc) · 1.28 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<stdio.h>
#include<stdlib.h>
/* Prime Frequency - 10789 */
typedef struct{
char c;
int f;
}Alpha_numerals;
int comp(Alpha_numerals *a,Alpha_numerals *b){
return a-b;
}
int isprime(int n){
int i;
if((n%2==0 && n!=2) || n == 1)
return 0;
for(i=3;i<=sqrt(n);i+=2)
if(n%i==0)
return 0;
return 1;
}
main(){
int i,c=0,T,size,flag,(*cmp)() = comp;
char str[2002];
Alpha_numerals A[62];
scanf("%d",&T);
for(;T>0;T--){
for(i=0;i<62;i++)
A[i].f = 0;
flag = 0;
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
if(isupper(str[i]))
{
A[str[i]-'A'+10].f++;
A[str[i]-'A'+10].c = str[i];
}
else
if(islower(str[i]))
{
A[str[i]-'a'+36].f++;
A[str[i]-'a'+36].c = str[i];
}
else
{
A[str[i]-'0'].f++;
A[str[i]-'0'].c = str[i];
}
qsort(A,62,sizeof(Alpha_numerals),cmp);
printf("Case %d: ",++c);
for(i=0;i<62;i++)
if(isprime(A[i].f))
{
putchar(A[i].c);
flag = 1;
}
if(!flag)
puts("empty");
else
putchar('\n');
}
}