UVa 10789 - Prime Frequency -- 模拟
2016-05-08 21:47
435 查看
就是求(0-9)、(A-Z)、(a-z)中字符数为素数的输出,没有一个的输出empty
我是利用映射来求得,0的Ascll为48 z的Ascll为122
我是利用映射来求得,0的Ascll为48 z的Ascll为122
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; int prime(int x){ int i; if(x==1||x==0) return 0; for(i=2;i<x;i++){ if(x%i==0) return 0; } return 1; } char p[2001]; int s[125]; int main(){ int t,i,j,Case=1; int num; scanf("%d",&t); while(t--){ memset(s,0,sizeof(s)); scanf("%s",&p); num=0; for(i=0;p[i]!='\0';i++) s[p[i]-'0']++; printf("Case %d: ",Case++); for(i=0;i<=125;i++){ if(prime(s[i])){ printf("%c",i+'0'); num++; } } if(num==0) printf("empty"); printf("\n"); } return 0; }
相关文章推荐
- GUI
- GUI.菜单栏
- UI基础_UISearchBar
- uestc1041Hug the princess
- hdoj--1530--Maximum Clique(最大团)
- Genuino 101无法下载程序的问题
- HDU 3397 Sequence operation(区间合并)
- leetcode n-queens
- *关于阿拉伯国家的UI适配问题
- 轻量级应用开发之(10) UINavigationController导航控制器
- UVA 1584 - Circular Sequence(环状序列)(字典序)
- HDU 2818 Building Block 加权并查集
- iOS UIKit:CollectionView之设计 (1)
- CGRectInset CGRectOffset UIEdgeInsetsInsetRect
- uestc1039
- XMG UIBezierPath与CGContextRef
- Android Volley完全解析(三),定制自己的Request
- Android之十二微信UI界面设计
- UID卡修改&UID锁死修复
- Android高级UI之自定义复合控件--标题栏