#include <stdio.h>
#include <string.h>
#include <stdlib.h>
bool prime[3000];
char input[2005];
int gen(int n)
{
int i, j;
memset(prime,true,n);
prime[0] = prime[1] = false;
for (i=4 ; i<n ; i+=2)
prime[i]=false;
for (i=3 ; i*i<n ; i+=2)
{
if (prime[i]==true)
{
for (j=i*i ; j<n ; j+=(2*i))
{
prime[j]=false;
}
}
}
return 0;
}
int cmp(const void *a, const void *b)
{
return (*(const char *)a-*(const char *)b);
}
int main()
{
gen(3000);
int t, i, j, kounter=1, len, val=0;
scanf("%d",&t);
while (t--)
{
scanf("%s",input);
printf("Case %d: ",kounter++);
len=strlen(input);
val=0;
qsort(input,len,sizeof(char),cmp);
for (i=0 ; i<len ; )
{
for (j=i ; input[j]==input[i] ; j++);
if (prime[j-i]==true)
{
printf("%c",input[i]);
val++;
}
i=j;
}
if (!val)
printf("empty");
printf("\n");
}
return 0;
}
Saturday, September 04, 2010
[UVa] 10789 - Prime Frequency
I tried to solve this problem at the very start of my UVa solving sessions. Then I used a stupid method, bubble sort, non sieve etc. Well, that's what you call improvement I guess, solving it the smarter way.
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Install MinGW GCC Port on Windows. 1. Just go to this address [ http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ ]...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.