历届试题 带分数

来源:互联网 发布:上海知金教育 编辑:程序博客网 时间:2024/06/04 19:09
问题描述

100 可以表示为带分数的形式:100 = 3 + 69258 / 714。

还可以表示为:100 = 82 + 3546 / 197。

注意特征:带分数中,数字1~9分别出现且只出现一次(不包含0)。

类似这样的带分数,100 有 11 种表示法。

输入格式

从标准输入读入一个正整数N (N<1000*1000)

输出格式

程序输出该数字用数码1~9不重复不遗漏地组成带分数表示的全部种数。

注意:不要求输出每个表示,只统计有多少表示法!

样例输入1
100
样例输出1
11
样例输入2
105
样例输出2

6

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
int cnt=0,n,k,vis[10],t,tem,v[10],l=0,num=0,num1;
long  long c[11]={0,10,100,1000,
10000,100000,1000000,10000000,100000000,
1000000000,10000000000};
cin>>n;
for(k=1;k<n;k++){
num=0;
memset(vis,0,sizeof(vis));
tem=k;
l=0;
while(tem>0){
l++;
t=tem%10;
if(!t)
goto Endl;
tem/=10;
if(vis[t])
goto Endl;
else
vis[t]++;
num++;
}
for(int i=1;i<c[(9-l)/2];i++){
num1=num;
memcpy(v,vis,10*sizeof(int));
tem=i;
while(tem>0){
t=tem%10;
if(!t)
goto End;
tem/=10;
if(v[t])
goto End;
else
v[t]++;
num1++;
}
tem=i*(n-k);
while(tem>0){
t=tem%10;
if(!t)
goto End;
tem/=10;
if(v[t])
goto End;
else
v[t]++;
num1++;
}
if(num1==9){
cnt++;
// cout<<k<<"+"<<i*(n-k)<<"/"<<i<<endl;
}
End:  ;
}
Endl:  ;
}
cout<<cnt<<endl;
return 0;
}

0 0
原创粉丝点击