![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//**************************************
Problem: HEU 1025 Persistent Numbers
Time: 0.1350 s
Memory: 540 k
Accepted Time: 2009-05-17 16:14:31
Tips: 高精度除法
**************************************/
#include <stdio.h>
#include <string.h>
bool judge(char *p,int n)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int temp=0;
for(int i=0;p[i]!=0;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp*=10;
temp+=p[i]-'0';
if(temp>=n)temp%=n;
}
temp%=n;
if(temp==0)return 1;
else return 0;
}
void div(char *a,int n)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int len=strlen(a),temp=0,count=0,i;
char *s=new char[len+1];
for(i=0;a[i]!=0;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp*=10;
temp+=a[i]-'0';
s[count++]=temp/n+'0';
temp%=n;
}
s[count]=0;
for(i=0;s[i]=='0';i++);
strcpy(a,s+i);
delete []s;
}
int main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
char a[1009];
int b[1009],i,j;
while(1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%s",a);
if(strcmp(a,"-1")==0)break;
if(strlen(a)==1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
printf("1%s\n",a);
continue;
}
int count=0;
for(i=9;i>=2;i--)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
while(judge(a,i))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
b[count++]=i;
div(a,i);
}
}
if(a[1]!=0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
printf("There is no such number.\n");
continue;
}
for(i=count-2;i>=0;i--)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(j=0;j<=i;j++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(b[j]>b[j+1])
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
for(i=0;i<count;i++)printf("%d",b[i]);
printf("\n");
}
return 0;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
posted @
2009-05-17 16:22
主函数
阅读(
243)
评论()
编辑
收藏
举报