UVa834 Continued Fractions【连分数】
来源:互联网 发布:企业数据架构设计 编辑:程序博客网 时间:2024/05/21 12:39
问题链接:UVa834 Continued Fractions。
问题简述:参见上述链接。
问题分析:
这是一个分数转换为连分数的问题。
需要了解和掌握有关连分数的概念与表示方式,可以查看中英文版的维基百科的“连分数”。
剩下的就是简单的分数计算问题了。程序说明:
需要考虑特例的情况,例如,分数实际上是整数的情况。
程序中不考虑约分的问题。
程序中的迭代计算过程尽可能地简洁。
题记:把功能封装到函数是一种好的做法,程序逻辑更加简洁。
AC的C++语言程序如下:
/* UVa834 Continued Fractions */#include <iostream>using namespace std;void fraction2continuedfraction(int n, int d){ int nextd; char separator = ';'; if(n % d == 0) printf("[%d]\n", n / d); else { printf("["); printf("%d", n / d); nextd = n % d; n = d; d = nextd; while(d != 0) { printf("%c", separator); printf("%d", n / d); nextd = n % d; n = d; d = nextd; separator = ','; } printf("]\n"); }}int main(){ int n, d; while(cin >> n >> d) { fraction2continuedfraction(n, d); } return 0;}
阅读全文
0 0
- UVa834 Continued Fractions【连分数】
- Continued Fractions
- 连分数(continued fraction)
- uva 834 - Continued Fractions
- UVa 834 - Continued Fractions
- [CF]-Continued Fractions
- CodeForces:305B Continued Fractions
- CF 305B Continued Fractions
- Gym 100641A Continued Fractions || 简单数学题
- codeforces 305B. Continued Fractions(数学)
- Gym 100641A Continued Fractions 模拟|签到
- Codeforces Round #184 (Div. 2) B. Continued Fractions
- Codeforces Round #184 (Div. 2)-B. Continued Fractions
- Problem E Codeforces Round #184 (Div. 2) B. Continued Fractions
- codeforces 305B. Continued Fractions (递归的思想)
- 连分数
- 连分数
- 连分数
- 离散题目4
- 基础技术篇 2 —— RFID技术(二)
- jsp页面input框中值或事件的操作方式
- Linux添加环境变量与GCC编译器添加INCLUDE与LIB环境变量
- Tomcat 自带的 JDBC 连接池官方文档中文版
- UVa834 Continued Fractions【连分数】
- jsp页面radio框中值操作方式
- 破解MyEclipse2015 stable3.0(亲测可用)
- pandas学习笔记
- Failed to load webpage with error: The request timed out.
- Win7 64下Apache2.4.25+PHP7.1.5的安装和配置以及启动服务
- PyTorch学习系列(四)——Tensor 和 Variable
- jsp页面select框中值或事件操作方式
- SDUT 3804 离散题目10