f91
来源:互联网 发布:如何保护膝盖关节 知乎 编辑:程序博客网 时间:2024/04/29 11:20
Background
McCarthy is a famous theorician of computer science. In his work, he defined a recursive function, called f91, that takes as input a positive integer N and returns a positive integer defined as follows:
- If N ≤ 100, then f91(N) = f91(f91(N+11));
- If N ≥ 101, then f91(N) = N-10.
The Problem
Write a program, that computes McCarthy's f91.
The Input
The input tests will consist of a series of positive integers, each integer is at most 1,000,000. There will be at most 250,000 test cases. Each number is on a line on its own. The end of the input is reached when the number 0 is met. The number 0 shall not be considered as part of the test set.
Output
The program shall output each result on a line by its own, following the format given in the sample output.
Sample Input 500
91
0
Sample Output f91(500) = 490
f91(91) = 91
Hint
Huge input and output, scanf( ) and printf( ) are recommended.
Source: UVA
my code:
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
while (n != 0){
if (n < 100 && n > 0){
cout << "f91(" << n << ") = " << 91 << endl;
}
else if (n >= 101){
cout << "f91(" << n << ") = " << n-10 << endl;
}
cin >> n;
}
return 0;
}
- f91
- f91
- UVA 10696 - f91
- UVa 10696 - f91
- UVa 10696 f91 (water ver.)
- [G联赛总决赛] Super vs F91 (5)
- [G联赛总决赛] Super vs F91 (4)
- [G联赛总决赛] Super vs F91 (3)
- [G联赛总决赛] Super vs F91 (2)
- [G联赛总决赛] Super vs F91 (1)
- 在SQL查询分析器中操作硬盘文件?
- 如何求供应商相同时,某列临近2个值的和(第一条记录除外),并将值放如某一列中?
- Advanced Test in C and Embedded System Programming
- 加几个笑话,调剂调剂!呵呵
- 自己动手写C#控件
- f91
- DataGrid输出到Excel并进行格式化处理
- Sql Server中的日期与时间函数
- T-SQL 生成的公历年历 (写在了存储过程中了)
- 【农历】计算方法--- (阳历转阴历)
- 在.Net中调用Sql Server存储过程
- IP地址与机器名的相互查找
- 在.net中访问硬盘中的.text文件,并用于滚动显示
- KAVA 恩,简单的脚本语言,HOHO