【NYOJ】[62]笨小熊
2016-01-28 20:38
197 查看
本来挺简单的一题
结果想多了……
出了一些偏差
[code]#include<stdio.h> #include<math.h> int main() { int T; scanf("%d",&T); getchar(); while(T--) { int a[26]= {0}; char c; while(c=getchar()) { if(c<'a'||c>'z') break; else { ++a[c-'a']; } } int max=0,min=120; for(int i=0; i<26; i++) { if(!a[i]) continue; else { if(max<a[i]) max=a[i]; if(min>a[i]) min=a[i]; } } int i,m=max-min; if(m<2) i=0; else { for(i=2; i<=sqrt(m); i++) if(m%2==0) break; } if(i<=sqrt(m)) printf("No Answer\n0\n"); else printf("Lucky Word\n%d\n",m); } return 0; }
还是感觉标程写的好乱
自己写了一个寻找除0之外的最小值的函数
[code]#include<iostream> #include<string> #include<algorithm> #include<numeric> using namespace std; bool isPrime(int n) { if(n==0) return false; if(n==1) return false; if(n==2) return true; for(int i=2; i*i<=n; i++) { if(n%i==0) return false; } return true; } int min_e(int *p,int *q) { int m=1000; for(int* i=p; i!=q; i++) { if(*i<m && *i!=0) m=*i; } return m; } int main() { int n; string str; cin>>n; while(n--) { int count[26]= {0}; cin>>str; for(int i=0; i!=str.size(); ++i) { ++count[str[i]-'a']; } int nn=*max_element(count,count+26)-min_e(count,count+26); if(isPrime(nn)) cout<<"Lucky Word"<<endl<<nn<<endl; else cout<<"No Answer"<<endl<<0<<endl; } }
题目地址:【NYOJ】[62]笨小熊
相关文章推荐
- setBackgroundResource导致Padding失效,settextsize
- Android 6.0 inflate过程分析
- Exception:org.eclipse.m2e.wtp.MarkedException: Unable to configure OHBC
- Inf2Cat应用的参数使用详细介绍
- UVA 10561 Treblecross(博弈论)
- 反向不归零码NRZI
- LeetCode279. Perfect Squares
- 初学者必看 RS422串口通信
- C++:const和指针
- Coroutine,你究竟干了什么?
- 整理Ruby相关的各种概念(rvm, gem, bundle, rake, rails等)
- 【NKs 1042】合唱队形
- Java-----jar反编译修改重新打包
- 判断一个数是否为奇数
- 前端笔记九,背景、边框和补丁相关属性
- 随便说说
- 为Eclipse添加PyDev插件
- 献给初学iOS的小盆友们——微博app项目开发之十四转发微博修正以及添加微博工具条
- struts2路径问题
- Unity3d之剥离 alpha 通道