[UVA] 10789 - Prime Frequency@Morris' Blog|PChome Online 人新台
2011-12-17 10:03:40| 人2,716| 回0 | 上一篇 | 下一篇

[UVA] 10789 - Prime Frequency

0 收藏 0 0 站台

  Prime Frequency 

Given a string containing only alpha-numerals (0-9, A-Z and a-z) you have to count the frequency (the number of times the character is present) of all the characters and report only those characters whose frequency is a prime number. A prime number is a number, which is divisible by exactly two different integers. Some examples of prime numbers are 2, 3, 5, 7, 11 etc.

Input 

epsfbox{p10789.eps}

The first line of the input is an integer T ( 0 < T < 201) that indicates how many sets of inputs are there. Each of the next T lines contains a single set of input.

The input of each test set is a string consisting alpha-numerals only. The length of this string is positive and less than 2001.

Output 

For each set of input produce one line of output. This line contains the serial of output followed by the characters whose frequency in the input string is a prime number. These characters are to be sorted in lexicographically ascending order. Here ``lexicographically ascending" means ascending in terms of the ASCII values. Look at the output for sample input for details. If none of the character frequency is a prime number, you should print `empty' (without the quotes) instead.

Sample Input 

3 ABCC AABBBBDDDDD ABCDFFFF 

Sample Output 

Case 1: C Case 2: AD Case 3: empty


 
作法 : 找的字元

#include<stdio.h>
int main() {
    int prime[2002] = {0};
    int i, j, C = 0, t;
    prime[0] = prime[1] = 1;
    for(i = 2; i < 2002; i++)
        if(prime[i] == 0) {
            for(j = 2; i*j < 2002; j++)
                prime[i*j] = 1;
        }
    char s[2002];
    scanf("%d", &t);
    while(t--) {
        scanf("%s", s);
        int asci[128] = {0};
        for(i = 0; s[i]; i++)
            asci[s[i]]++;
        printf("Case %d: ", ++C);
        for(i = 0, j = 0; i < 128; i++)
            if(prime[asci[i]] == 0)
                printf("%c", i), j++;
        if(j == 0)    printf("empty");
        puts("");
    }
    return 0;
}

台: Morris
人(2,716) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA] 136 - Ugly Numbers
此分上一篇:[UVA] 1121 - Subsequence

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86