poj 2325 Persistent Numbers
简单的贪心和高精度运算,主要还是要读懂题。
#include"iostream"
#include"stdio.h"
#include"string"
#include"string.h"
#include"cmath"
#define mx 5005
using namespace std;
int cnt[];
char num[mx];
char temp[mx];
bool div(int mod)
{
int i,j,k=,pre=,s;
for(i=;num[i]!='\0';i++)
{
s=pre*+(num[i]-'');
temp[k++]=(s/mod)+'';
pre=s%mod;
}
temp[k]='\0';//一定要给字符串加上一个结束符,这个真的是非常重要的!!!
if(pre==)
{
if(temp[]=='')
strcpy(num,temp+);
else
strcpy(num,temp);
return true;
}
else
return false;
}
int main()
{
int i,j,k;
while(cin>>num,strcmp(num,"-1")!=)
{
memset(cnt,,sizeof(cnt));
if(strlen(num)==)
{cout<<""<<num<<endl;continue;}
for(i=;i>=;i--)
{
while(div(i)) cnt[i]++;
}
if(strlen(num)!=)
cout<<"There is no such number."<<endl;
else
{
for(i=;i<=;i++)
{
while(cnt[i])
{cout<<i;cnt[i]--;}
}
cout<<endl;
}
}
return ;
}
poj 2325 Persistent Numbers的更多相关文章
- poj 2325 Persistent Numbers (贪心+高精度)
把输入数字每次从9-2除,能整除则记录该数字,最后从小到大输出. 应该算是水题,不过窝第一次写高精度除法,虽然1A,不过中间改了好多次. /****************************** ...
- POJ 2325 Persistent Numbers#贪心+高精度除法
(- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...
- POJ - 3652 Persistent Bits
“模拟”类型,题型容易,使用bitset库对二进制逐位操作,初始化.十进制转二进制(unsigned int).位操作. POJ - 3652 Persistent Bits Time Limit: ...
- Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)
一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...
- POJ 1142 Smith Numbers(史密斯数)
Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...
- poj 3641 Pseudoprime numbers
题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- poj 3641 Pseudoprime numbers Miller_Rabin测素裸题
题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为po ...
随机推荐
- EditText根据焦点弹出软键盘
//每次启动都清除焦点 myCourse_roomId_input.setText(""); myCourse_roomId_input.clearFocus(); //判断是否获 ...
- Visual Studio vs软件下载 vax Visual Assist X VAssistX
Visual_Studio_2008_Team_Suite简体中文正式版及补丁下载链接:http://pan.baidu.com/s/1jGvOotg 密码:y6ic Visual Studio 20 ...
- SPOJ PHRASES 后缀数组
题目链接:http://www.spoj.com/problems/PHRASES/en/ 题意:给定n个字符串,求一个最长的子串至少在每个串中的不重叠出现次数都不小于2.输出满足条件的最长子串长度 ...
- 同步、更新、下载Android Source & SDK from 国内镜像站
转自: 同步.更新.下载Android Source & SDK from 国内镜像站 Download the android source from china mirrors 以 ...
- web api :Routing in ASP.NET Web API
引 Web API 和SignalR都是在服务层. If you are familiar with ASP.NET MVC, Web API routing is very similar to M ...
- PLSQL看oracle中汉字显示乱码
首先执行语句 select * from V$NLS_PARAMETERS 查看第一行中PARAMETER项中为NLS_LANGUAGE 对应的VALUE项中是否为SIMPLIFIED CHINES ...
- ol新属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Codeforces 627A XOR Equation(思路)
题目大概说两个正整数a.b,已知s=a+b以及x=a xor b的值,问有几种a.b这样的数对. 我知道异或相当于无进位的加法,s-x就是其各个位置的进位,比如s-x=1010,那就表示a和b的第1位 ...
- My97DatePicker控件
本文只做了功能说明,详细请看http://www.my97.net/dp/demo/index.htm 二. 功能及示例 1. 常规功能 支持多种调用模式 除了支持常规在input单击或获得焦点调用外 ...
- Linux下使用vsftp
参考网址: http://wenku.baidu.com/view/4339434bc850ad02de80419c.html?re=view root用户无法ftp登录,显示530 Permissi ...