博文
c/c++基礎習題解決(3)--the 3n+1 problem(2007-07-27 21:33:00)
摘要:问题描述:
这是一个古老的猜想:给定任何一个正整数n,对它进行以下操作:
n是偶数:n=n/2
n是奇数:n=3*n+1
这样经过多步操作后,最后必定变为1
如对13进行操作: 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
一共经历了9次操作,则称13这个数的周期是9
输入:
多组测试数据,每组一行,一行里有两个数m和n,请你找出m和n之间(包括m,n)的周期最大的数的周期
其中m,n均小于1e5
输出:
m,n之间周期最大的数的周期,一个结果单独占一行
样例输入:
1 10
2 3
30 100
样例输出:
19
7
118
难度:very easy
習題來源:飞燕之家C/C++语言学习论坛
解決代碼:
// NPlusOnePro.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <malloc.h>
#include <memory.h>
#include <assert.h>
#define INT_UPLIMIT  ......
c/c++基礎習題解決(2)--因式分解問題(2007-07-27 21:24:00)
摘要:习题 12:因子分解★
输入n(1 <= n <= 1e9),有多组测试数据:
616
27
输出:
616 = 2^3 * 7 * 11
27 = 3^3
(注意输出空格,但行末不要有空格)
难度:for beginner
--習題來源:飛燕之家c/c++學習論壇
解決代碼:
//因式分解
#include <stdio.h>
#include <wchar.h>
#define PRIME_MAXCOUNT 500
#define RESULT_MAXCOUNT 10
#define FIRST_NUM 2
//foward decl......
c/c++基礎習題解決(1)--找出第3名学生的成绩(2007-07-27 21:19:00)
摘要:ACM大学刚考完大学英语4级考试,想知道全校第3名学生的成绩是多少?
如果最高分有好多个学生,则相同成绩的学生都算第一名;同理,如果第二高分的有多个学生,都算第二名。
当然这是简单题,请你快速编一个程序找到第3名的成绩。
输入:输入有多组,每组有2行,第一行是学生人数N(1<=N<10000),第二行有N个整数,分别表示每个学生的成绩(0到1e9)。当输入的N为0的时候结束程序。
输出:对于每组输入,输出只有一行,即第3名学生的成绩,如果找不到,则输出No such score !
Sample input:
10
90 84 90 60 70 65 73 85 98 98
5
90 90 89 90 90
0
Sample output:
85
No such score !
难度:for beginner
Time limit: 50ms Memory: 200K
--試題來源:飛燕之家c/c++學習論壇
解決代碼:
#include <iostream>
#include <assert.h>
#include <memory.h>
using namespace std;
//define some constants
const int MAXNUM &......
[原创]学生管理系统(java)(2006-08-03 22:26:00)
摘要:http://www.angeltears.cn/dispbbs.asp?boardID=21&ID=953&page=1......
[原创]学生管理系统(java)(2006-08-03 22:25:00)
摘要:http://www.angeltears.cn/dispbbs.asp?boardID=21&ID=953&page=1......
[转载]数据库的所有连接方法(2006-08-03 22:23:00)
摘要:http://www.angeltears.cn/dispbbs.asp?boardID=12&ID=945&page=1......
c++中链表操作(2006-08-03 22:22:00)
摘要:http://www.angeltears.cn/dispbbs.asp?boardID=20&ID=130&page=1......
[原创](C++)循环链表操作及应用(约瑟夫环问题)(2006-08-03 22:21:00)
摘要:http://www.angeltears.cn/dispbbs.asp?boardID=20&ID=928&page=1......
[原创]c++排序算法实现(2006-08-03 22:20:00)
摘要:http://www.angeltears.cn/dispbbs.asp?boardID=20&ID=929&page=1......