// UVa 10789 - Prime Frequency #include <iostream> #include <string> #include <string.h> #include <stdio.h> using namespace std; int main() { // primes bool prime[2001]; memset(prime, true, sizeof(prime)); prime[0] = false; prime[1] = false; for (int i = 2; i <= 44; i++) { for (int j = i * i; j < 2001; j += i) prime[j] = false; } // int tt; cin >> tt; string line; getline(cin, line); for (int t = 1; t <= tt; t++) { getline(cin, line); int f[256]; memset(f, 0, sizeof(f)); for (int i = 0; i < line.length(); i++) { f[line[i]]++; } cout << "Case " << t << ": "; bool empty = true; for (char c = '0'; c <= '9'; c++) if (prime[f[c]]) { cout << c; empty = false; } for (char c = 'A'; c <= 'Z'; c++) if (prime[f[c]]) { cout << c; empty = false; } for (char c = 'a'; c <= 'z'; c++) if (prime[f[c]]) { cout << c; empty = false; } if (empty) cout << "empty"; cout << endl; } return 0; }
Wednesday, September 23, 2015
UVa 10789 - Prime Frequency
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment