UVA 725(p182)----Division
来源:互联网 发布:飞行仪表显示软件开发 编辑:程序博客网 时间:2024/05/16 07:41
#include<cstdio>#include<iostream>#include<cstring>using namespace std;typedef long long LL;int n,cc[10],dd[10],cas=0;LL temp1,temp2;bool flag;bool check(LL a,LL b){ int top1=0,top2=0; memset(cc,0,sizeof(cc)); memset(dd,0,sizeof(dd)); while(a>0) { top1++; cc[top1]=a%10; a/=10; } while(top1<5) { top1++; cc[top1]=0; } while(b>0) { top2++; dd[top2]=b%10; b/=10; } while(top2<5) { top2++; dd[top2]=0; } for(int i=1;i<=5;i++) for(int j=1;j<=5;j++) if((cc[i]==dd[j])||((cc[i]==cc[j])&&(i!=j))||((dd[i]==dd[j])&&(i!=j))) return 0; return 1;}int main(){ // freopen("in.in","r",stdin); //freopen("out.out","w",stdout); while(scanf("%d",&n)==1&&n) { flag=0;cas++; if(cas!=1) puts(""); for(int a=0;a<=9;a++){ for(int b=0;b<=9;b++) if(a!=b) for(int c=0;c<=9;c++) if(a!=c&&b!=c) for(int d=0;d<=9;d++) if(a!=d&&b!=d&&c!=d) for(int e=0;e<=9;e++) if(a!=e&&b!=e&&c!=e&&d!=e) { temp1=e+d*10+c*100+b*1000+a*10000; temp2=temp1*n; if(temp1>99999||temp2>99999) break; if(check(temp1,temp2)) { flag=1; for(int i=5;i>=1;i--) cout<<dd[i]; cout<<" / "; for(int i=5;i>=1;i--) cout<<cc[i]; cout<<" = "; cout<<n<<endl; } } } if(!flag) cout<<"There are no solutions for "<<n<<"."<<endl; } return 0;}题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666
0 0
- UVA 725(p182)----Division
- UVA 725 - Division
- UVA 725 - Division
- UVa 725 - Division
- UVA - 725 Division
- UVa 725 - Division
- UVa 725 Division
- UVa 725 - Division
- Uva 725 Division
- UVA-725除法-Division
- UVA - 725 Division
- uva 725 - Division
- Uva - 725 - Division
- UVA - 725 Division
- uva 725 Division
- 除法(Division, UVa 725)
- UVA 725 Division
- UVA 725 - Division
- Servlet_03_ServletConfig
- 操作系统----内存管理
- UVA 714(p244)----Copying Books
- chart控件的简单使用
- 接口回调-自己理解
- UVA 725(p182)----Division
- 加载内核模块,实现新的系统调用:遍历系统当前所有进程的任务描述符,并将pid组织成树状结构显示
- 欢迎使用CSDN-markdown编辑器
- POJ 3177 Redundant Paths(Tarjan_BCC+缩点)
- leetcode-115-Triangle
- RecyclerView的使用(3)之添加Header和Footer
- 贪心算法知识点补充
- Elcipse与MyEclipse
- CentOS下NTP时间服务器的架设和Windows客户端的配置(一)Linux服务器配置