pc/uva 110101/100 3n+1 problem(已解决)
来源:互联网 发布:us域名注册条件 编辑:程序博客网 时间:2024/05/16 23:55
ansic C:
#include <stdio.h>int iscorrect(int n);int length1(int n);void swap(int *p,int *q);int main(){ int i,j, m,n,flag,max; // char flag; while(scanf("%d %d",&i,&j) != EOF){ max = 0; n = i; m =j; if (i > j) swap(&i,&j); if(iscorrect(i) && iscorrect(j) ){ while (i <= j){ flag = length1(i); i++; if(flag> max) max = flag; } printf("%d %d %d\n",n,m,max); // printf("\n"); } else { printf("you inputting is error,please input again \n "); } } //system("pause");} int iscorrect(int n){ if (n> 0 && n < 1000000) return 1; else return 0; } int length1(int n){ int len; len = 1; while (n != 1){ if(n % 2 == 0){ len ++; n = n/2; } else { n = 3*n +1; len++; } } return len; } void swap(int *p,int *q){ int temp; temp = *p; *p = *q; *q = temp; }
需要注意的问题是:对于整数i,j,他们之间大小没有确定,所以我们要判断哪个大,哪个小。
- pc/uva 110101/100 3n+1 problem(已解决)
- UVa 100 Problem: The 3n+1 problem (PC 110101)
- PC/UVa 题号: 110101/100 3n+1 Problem
- PC/UVa 110101/100 3n+1 问题(3n+1 Problem)
- PC 110101 3n+1 Problem
- UVA 100 The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- Uva 100 3n+1problem
- uva 100 The 3n+1 problem
- UVa 100 - The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- uva 100 The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- UVa 100 The 3n + 1 problem
- uva--100 - The 3n + 1 problem
- UVa 100 - The 3n + 1 problem
- 外链做法及怎么注册域名
- 使用Automake和Autoconf生成Makefile
- awk---grep----sed
- Java调用C++编写的Dll
- 图解局域网共享设置步骤
- pc/uva 110101/100 3n+1 problem(已解决)
- Android Activity间的过渡动画
- Spring Java Configuration——用java代码来装配Spring
- 用算法实现将一个输入的数字颠倒(输入12345->54321),要求不调用任何系统函数,也不能将输入的数字转换为字符串作为中间过渡
- java反射学习(Reflection)
- struts+hibernate+spring 版本控制svn的URL地址
- SourceInsight使用技巧(转)
- 一个正整数分解成质因数
- Redis报错:ERR Operation against a key holding the wrong kind of value 解决处理