本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年3月12日 星期六

[UVa]10789:Prime Frequency

利用質數表和ASCII碼就可以快速解完此題。

[C](0.016)
#include<stdio.h>
#include<string.h>
int main()
{
int prime[2005] = {1, 1, 0, 0};
int i, j;
for( i = 2 ; i < 2001 ; i++ )
if( !prime[i] )
for( j = i*i ; j < 2001 ; j += i )
prime[j] = 1;
int T;
while( scanf( "%d", &T ) != EOF )
{
getchar();
char str[2005];
for( i = 1 ; i <= T ; i++ )
{
gets( str );
int strlength = strlen( str );
int ASCII[256] = {0};
for( j = 0 ; j < strlength ; j++ )
ASCII[str[j]]++;
printf( "Case %d: ", i );
int ok = 0;
for( j = 0 ; j < 128 ; j++ )
if( !prime[ASCII[j]] )
{
ok = 1;
printf( "%c", j );
}
if( !ok )
printf( "empty" );
printf( "\n" );
}
}
return 0;
}
view raw UVa10789.c hosted with ❤ by GitHub

0 意見:

張貼留言