4424. David’s Lucky Numbers
来源:互联网 发布:c语言中问号的用法 编辑:程序博客网 时间:2024/04/29 17:34
4424. David’s Lucky Numbers
Description
David loves lucky numbers. In his opinion, positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day David came across a positive integer N. Help him to find the least super lucky number which is not less than N.
Input
The first line contains an integer T (1<=T<=10), indicating the number of test cases.
Then, for each case, there is only a number N (1<=N<=10^9).
Output
For each case, print the super Lucky number that is more than or equal to N in one line.
Sample Input
2
4500
47
Sample Output
4747
47
做复杂了,开个整形数组就可以的,悲剧啊
#include <iostream>#include <string>#include <cmath>#include <cstring>#include <algorithm>using namespace std;int main(){ int t; cin>>t; while(t--) { string strn; cin>>strn; int len=strn.length(),shu=0,maxshu=0; for(int i=0;i<len;i++) shu+=(strn[len-1-i]-'0')*pow(10.0,i); for(int i=0;i<(len-1)/2+1;i++) maxshu+=4*pow(10.0,i); for(int i=(len-1)/2+1;i<len;i++) maxshu+=7*pow(10.0,i); if(shu>maxshu) { for(int i=0;i<=len/2;i++) cout<<"4"; for(int i=0;i<=len/2;i++) cout<<"7"; cout<<endl;continue; } if(len%2) { for(int i=0;i<=len/2;i++) cout<<"4"; for(int i=0;i<=len/2;i++) cout<<"7"; cout<<endl;continue; } string s="00000000000"; for(int i=0;i<len/2+1;i++) s[i]='4'; for(int i=len/2;i<len;i++) s[i]='7'; int a[11]; for(int i=0;i<len;i++) a[i]=s[i]-'0'; do { int shu2=0; for(int i=0;i<len;i++) shu2+=a[i]*pow(10.0,len-i-1); if(shu<=shu2) { cout<<shu2<<endl;break; } } while(next_permutation(a,a+len)); } return 0;}
- 4424. David’s Lucky Numbers
- Sicily 4424. David’s Lucky Numbers
- Sicily 4424. David’s Lucky Numbers
- Lucky Numbers
- Lucky Numbers
- Lucky Numbers
- [bnu] 4104 Lucky numbers
- hust1600 Lucky Numbers 小水题
- F: Lucky Numbers
- UVa11970 - Lucky Numbers
- HUST 1600 Lucky Numbers
- C - Lucky Numbers
- HUST 1600 Lucky Numbers
- Lucky Numbers(acm)
- C. Lucky Numbers
- hdu_5676_ztr loves lucky numbers
- hdoj5676ztr loves lucky numbers
- Lucky Numbers (easy)
- 个人喜欢的网站http://www.w3school.com.cn
- k-means简介
- BM算法图解
- Java生成验证码
- 兵王OL智力答题器
- 4424. David’s Lucky Numbers
- STL学习杂记
- JAXB
- HTML 5 参考手册,HTML 5 标准属性,HTML 5 事件属性
- 关于UV纹理坐标映(Texture Mapping)射原理
- framebuffer驱动
- 网友推荐的Symbian开发入门级教程
- C# winform 问题
- 日期函数相关的SQL总结datediff(),datepart()