喵宅苑 MewoGarden × 技术宅社区II | Z站 Z Station 棒棒哒纯文字二次元技术社区

正文

参与活动贴【禁水】

作者:Mr_Alex
不晓得这是干什么的请移步https://www.gn00.com/forum.php?mod=viewthread&tid=279549&page=1&extra=#pid15711393 先看完再来回帖 否则,你懂得 @20# 扣除20宅币+5宅贡献的说 @ou# 本帖已经设置本人可见,请放心回帖,回帖格式举例: 参与人ID(UID): Mr_Alex(293988) ——团体参与的请把所有人列出来 参与类型: A 编程题目类 / B 应用项目类 答案:........ 在本帖回帖后请移步 https://www.gn00.com/forum.php?mod=viewthread&tid=279549&page=1&extra=#pid15711393 贴子点击页面的参与,然后将你的本帖回帖的楼层填写进去提交,否则视为未参与@ou# 编程类: 1.题目:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程 找出1000以内的所有完数。 2.题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高? 3.题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。 4.题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大? 5.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? 6.编写反转字符串的程序,要求优化速度、优化空间。 7.题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润,求应发放奖金总数 8.题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下 的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。 9.题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。 10.选作题:设计并实现一个密码加密算法,要求加密后的密文不能依据程序而进行逆向解析(尽可能的不能被解析) 应用类: 权限管理系统 1、系统要对用户身份进行相当严格的安全验证机制;不同的用户要有不同的角色/职位;不同的角色要有不同的权限; 2、要能够直接针对某一个用户绑定特殊权限,即不通过角色绑定而为其指定权限; 3、一个用户可以绑定多个角色,同一个角色也可以被多个用户使用; 4、系统应当记录用户的登录信息,包括登录时间,登录IP等,以检测用户账号的安全性; 手机APP应用 1、从身边的生活入手,提出一种需求,对需求进行分析,确定需求的可行性 2、根据1的需求,设计并实现该手机APP(android/java/IOS选一即可) 选作题:找到一个自己喜欢的网站,说出自己喜欢这个站的理由(这个站好再哪里),尝试用自己熟悉的语言来实现这个站的主要功能(至少40%以上的主要功能) 关于回帖: A类题目的参赛者请直接在本帖回帖,直接贴代码即可 B类题目的参赛者,也需要回帖(为了以后方便发放奖励),但是不必贴代码,请将源码打包,我们将在5月15日前后公布接收源码的邮箱,敬请关注。 小提示: 你可以先在本帖回帖占楼,然后去报名帖报名,为了将来评分方便,请在报名的时候贴上你在本贴回帖的楼层。谢谢合作! 如果你在本帖已经占楼,请务必去报名并在活动结束前来本帖完善编辑答题,否则将视为水贴。在本帖水是会被扣分的撒 @100# 2013.05.15日: 现公布递交应用类答案的邮箱 alex@gn00.com ,请选择应用类题目的参与者及时递交答案。接受答案截止日期2013年6月15日。

回复

太简单了

作者:右眼
太简单了- -作为在学校上计算机竞赛的人来说#43t
查看回复

本帖最后由

作者:michaelan
[i=s] 本帖最后由 michaelan 于 2013-4-25 22:20 编辑 参与人ID(UID): michaelan(425509) 参与类型: A 编程题目类 答案:C++写的 虽然是新人但是态度认真的(^U^)ノ~YO (1)
#include <stdio.h> int main() { int ans[500]; int ans_count = 0; for (int i = 1; i <= 1000; i++) { bool check = true; int sum = 0; for (int j = 1; j < i; j++) if (i % j == 0) sum += j; if (sum == i) { ans[ans_count++] = i; printf("%d\n", i); } } return 0;
(2)
#include <stdio.h> int main() { double height = 100.0; double journey = 100.0; for (int i = 1; i < 10; i++) { journey += height; height /= 2.0; } height /= 2.0; printf("journey = %lf\nheight = %lf\n", journey, height); return 0; }
(3)
#include <stdio.h> int print(int a, char b) { char c; if (a == 1) c = 'x'; else if (a == 2) c = 'y'; else c = 'z'; printf("%c-%c\n", b, c); } int main() { int a, b, c; // 1:x 2:y 3:z for (a = 1; a <= 3; a++) for (b = 1; b <=3; b++) if (a != b) { c = 6 - a - b; if (a == 1 || c == 1 || c == 3) continue; print(a, 'a'); print(b, 'b'); print(c, 'c'); } return 0; }
(4)
#include <stdio.h> int main() { int age[6]; age[1] = 10; age[2] = age[1] + 2; age[3] = age[2] + 2; age[4] = age[3] + 2; age[5] = age[4] + 2; printf("age=%d\n", age[5]); return 0; }
(5)
#include <stdio.h> /* 就当是正整数排序吧 ,输入若干个数,以-1结尾 * 输出的话从小到大排序好了 * 选择的是插入排序咯,因为链表插入快嘛,要利用起来哟 */ struct My_Link { int val; My_Link* next; }; int main() { My_Link* head = new My_Link; head->val = -1; head->next = NULL; // input data and sort int a; scanf("%d", &a); while (a >= 0) { My_Link* new_node = new My_Link; new_node->val = a; new_node->next = NULL; My_Link* now = head->next; My_Link* last = head; while (now != NULL && now->val < a) { last = now; now = now->next; } new_node->next = last->next; last->next = new_node; scanf("%d", &a); } // print data My_Link* now_node = head->next; while (now_node != NULL) { printf("%d\n", now_node->val); now_node = now_node -> next; } // recover memory while (head != NULL) { now_node = head; head = head->next; delete now_node; } return 0; }
(6)
#include <stdio.h> #include <string.h> void s_reverse_n(char* s, int n) { for (int i = 0; i < n / 2; i++) { char p = s[i]; s[i] = s[n - i - 1]; s[n - i - 1] = p; } } int main() { char a[50]; strcpy(a, "Hello world."); s_reverse_n(a, strlen(a)); printf("%s\n", a); return 0; }
(7)
#include <stdio.h> int main() { double profit; printf("profit = $ "); scanf("%lf", &profit); double bonus = 0.0; if (profit <= 100000) bonus = profit * 0.1; else if (profit <= 200000) bonus = 10000 + (profit - 100000) * 0.075; else if (profit <= 400000) bonus = 17500 + (profit - 200000) * 0.05; else if (profit <= 600000) bonus = 27500 + (profit - 400000) * 0.03; else if (profit <= 1000000) bonus = 33500 + (profit - 600000) * 0.015; else bonus = 39500 + (profit - 1000000) * 0.01; printf("bonus = $ %lf", bonus); return 0; }
(8)
#include <stdio.h> int main() { int ans = 1; // 9 times for (int i = 0; i < 9; i++) { ans += 1; ans *= 2; } printf("%d\n", ans); return 0; }
(9)
#include <stdio.h> int main() { int a[50]; int n; int max_i, min_i; printf("Input N = "); scanf("%d", &n); printf("Input %d numbers : ", n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); max_i = 0; for (int i = 1; i < n; i++) if (a[i] > a[max_i]) max_i = i; int tmp = a[0]; a[0] = a[max_i]; a[max_i] = tmp; min_i = 0; for (int i = 1; i < n; i++) if (a[i] < a[min_i]) min_i = i; tmp = a[0]; tmp = a[n - 1]; a[n - 1] = a[min_i]; a[min_i] = tmp; for (int i = 0; i < n; i++) printf("%d ", a[i]); printf("\n"); return 0; }
(10)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /* 以下实现的是RSA算法的阉割版 * 当然看着代码是可以破解的,因为把解密用的密匙也写在这了,实际中,P和Q是可以抛弃的,使用N、e进行加密,使用N、d进行解密 */ const unsigned long long P = 12301; const unsigned long long Q = 3217; unsigned long long gcd(unsigned long long a, unsigned long long b) { if (b == 0) return a; else return gcd(b, a % b); } unsigned long long x, y; void extend_Eulid(unsigned long long a, unsigned long long b) { if(b == 0) { x = 1; y = 0; } else { extend_Eulid(b, a%b); unsigned long long temp = x; x = y; y = temp - a / b * y; } } void get_key(unsigned long long P, unsigned long long Q, unsigned long long &N, unsigned long long &e, unsigned long long &d) { N = P * Q; unsigned long long R1 = P - 1; unsigned long long R2 = Q - 1; unsigned long long R = R1 * R2; unsigned long long one = 1; e = (P + Q) * ((long long) rand()) / 65535; while (gcd(e, R) != 1) e = e + one; extend_Eulid(e, R); d = x % R; } // return a^b (mod c) unsigned long long power(unsigned long long a, unsigned long long b, unsigned long long c) { unsigned long long two = 2; unsigned long long res = 1; while (b > 0) { if (b % two == 1) res = (res * a) % c; a = (a * a) % c; b = b / two; } return res; } void encode(unsigned long long code[], int& code_len, char s[], int len, unsigned long long N, unsigned long long e) { unsigned long long M = 0; unsigned long long ONE_CHAR = 128; code_len = 0; int c = 0; for (int i = 0; i < len; i++) { M = M * ONE_CHAR + ((unsigned long long) s[i]); c++; if (c % 3 == 0) { code[code_len++] = M; M = 0; c = 0; } } if (c != 0) code[code_len++] = M; for (int i = 0; i < code_len; i++) { code[i] = power(code[i], e, N); } } void decode(unsigned long long code[], int code_len, char s[], int &len, unsigned long long N, unsigned long long d) { unsigned long long ONE_CHAR = 128; len = 0; int last_len = 0; for (int i = 0; i < code_len; i++) { unsigned long long M = power(code[i], d, N); while (M > 0) { s[len++] = (unsigned char) (M % ONE_CHAR); M = M / ONE_CHAR; } char q = s[last_len]; s[last_len] = s[len - 1]; s[len - 1] = q; last_len = len; } } int main() { srand(time(0)); unsigned long long N, e, d; get_key(P, Q, N, e, d); printf("N=%I64d\ne=%I64d\nd=%I64d\n", N, e, d); printf("-----------------------------\n"); printf("Please input a string (length <= 20):\n"); char s[20]; gets(s); unsigned long long c[20]; int c_len = 0; encode(c, c_len, s, strlen(s), N, e); printf("After coding m = "); for (int i = 0; i < c_len; i++) printf("%I64d ", c[i]); printf("\n"); printf("After decoding s = "); int len; char t[20]; decode(c, c_len, t, len, N, d); for (int i = 0; i < len; i++) printf("%c", t[i]); printf("\n"); return 0; }
查看回复

数的各个因子和

作者:jains521
[mw_shl_code=cpp,true]#include <iostream> using namespace std; //题目1的答案: int ThePerfectnumber() { int has_count=0; int max_number=1000; int __tmp=1; //数的各个因子和. int opnum=0; //overplus number 剩余的最大数. 如8/2剩余4 剩余最大的数为4 for(int i=3; i<=max_number; i++) { opnum=i; __tmp=1; for(int j=2; j<opnum; j++) { if( !(i%j) ) { __tmp =__tmp+ i / j + j; opnum=i/j; // cout <<i<<" "<<__tmp<<" " <<opnum<<endl; } if( __tmp > i ) //当完数和大于i则不是完数. { __tmp=1; break; } } if( __tmp == i ) { // cout <<i<<endl; has_count++; } // system("pause"); } return has_count; } //题目2的答案: float TheBall(float hight, int n) { if( !(n-1)) { cout <<"2: 第十次反弹:"<<hight/2<<endl; return hight/2; } else { float a=hight+hight/2+TheBall(hight/2, n-1); //cout <<hight<<endl; return a; } } //题目3的答案: void act(int peple) { switch(peple) { case 1: cout <<" vs x"<<endl; break; case 2: cout <<" vs y"<<endl; break; case 3: cout <<" vs z"<<endl; break; default: break; } } void ThePinpon() { int size=6; int x=1, y=2, z=3; int a=0, b=0, c=0; c=size-x-y; a=size-c-x; b=size-c-a; cout <<"\ta"; act(a); cout <<"\tb"; act(b); cout <<"\tc"; act(c); } //题目4的答案: int TheAge(int n) { if(!n) return 10; else return TheAge(n-1) + 2; } int main() { /*第一题:*/ cout <<"1: 1000内共有:"<<ThePerfectnumber()<<"个完数."<<endl; /*第二题:*/ cout <<"2: "<<TheBall(100, 10)<<endl; /*第三题:*/ cout <<"3:"; ThePinpon(); /*第四题:*/ cout <<"4: "<<TheAge(4)<<endl; return 0; }[/mw_shl_code]
查看回复

本帖最后由

作者:sora酱_
[i=s] 本帖最后由 sora酱_ 于 2013-5-3 08:21 编辑 参与人ID(UID): sora酱_ 参与类型: A 编程题目类 答案: 嗯嗯...其实是志在参与而已...!88! 用滴是python嗯..( ̄▽ ̄") ...以function滴形式写米问题吧?~ 也米有规定output滴格式.....吧?~... 题目1: [mw_shl_code=python,true]def question1(): total = 0 for i in range(1, 1000): total = 0 for j in range(1, i // 2 + 1): if i % j == 0: total += j if total == i: print(i)[/mw_shl_code] 才8会说其实这题是室友教滴呢~(* ̄∇ ̄)ノ~ 题目2: [mw_shl_code=python,true]def question2(): height = 100 distance = 0 for i in range(10): distance += height height = height / 2 if i != 9: distance += height return (distance, height)[/mw_shl_code] 题目3: [mw_shl_code=python,true]def question3(): teamOne = ['a', 'b', 'c'] teamTwo = ['x', 'y', 'z'] result = {} result['c'] = random.choice(teamTwo) while result['c'] == 'x' or result['c'] == 'z': result['c'] = random.choice(teamTwo) teamTwo.remove(result['c']) result['a'] = random.choice(teamTwo) while result['a'] == 'x': result['a'] = random.choice(teamTwo) teamTwo.remove(result['a']) result['b'] = random.choice(teamTwo) return result[/mw_shl_code] 题目4: [mw_shl_code=python,true]def question4(): return helperForQ4(5) def helperForQ4(numPpl): if numPpl == 1: return 10 else: return helperForQ4(numPpl - 1) + 2[/mw_shl_code] 题目5: 真滴要贴么...超长滴赶脚啊...这个其实是咱上次期末作业滴一部分...于是写了好长...( ̄▽ ̄") ...就把貌似符合滴贴上来吧... 先图解下... 大概是这样滴...OTZ.. search的时候从head开始, 如果右边的比要找的item大就向下, 小就向右. 于是可以优化速度~╮( ̄▽ ̄")╭~ 每个node都有2个reference, right和down. 然后层数是随机的...在insert 的method里面随机+8知道多少层... 图里面里面大框的数字是储存的item, 小框数字是skip number, 就是离同一排的下一个node相隔了多少个node. skip number其实是用于用index来找item的...不过题目米要求咱就8贴上来了... 贴上来的部分请无视self.skip这个attribute... [mw_shl_code=python,true]class SkipList: def __init__(self, container=[], prob=0.5): self.prob = prob self._tail = _TailNode() self._head = self._bottom = _HeadNode(self._tail, self._tail) for item in container: self.insert(item) def __contains__(self, item): return item in self._head def __iter__(self): return _SkipIter(self._bottom) def insert(self, item): while inserted is not None: inserted = _SkipNode(item, inserted, inserted.right, inserted.skip) self._head = _HeadNode(self._head, inserted, self._head.skip) if random.random() >= self.prob: inserted = None if self._head.right != self._tail: self._head = _HeadNode(self._head, self._tail, self._head.skip + self._head.right.skip) def remove(self, item): self._head.remove(item) while self._head.down.right == self._tail: self._head = self._head.down class _SkipNode(object): def __init__(self, item, down, right, skip): self.item = item self.down = down self.right = right self.skip = skip def __contains__(self, item): pred = self while pred.right.item < item: pred = pred.right return pred.right.item == item or item in pred.down def insert(self, item, prob): this_skip = 0 pred = self while pred.right.item < item: this_skip += pred.skip pred = pred.right inserted, below_skip = pred.down.insert(item, prob) pred.skip += 1 if inserted is not None: pred.right = _SkipNode(item, inserted, pred.right, pred.skip - below_skip) pred.skip = below_skip if random.random() < prob: return (pred.right, this_skip + pred.skip) return (None, 0) def remove(self, item): pred = self while pred.right.item < item: pred = pred.right removed = pred.down.remove(item) if pred.right.item == item: removed = pred.right pred.right = removed.right pred.skip += removed.skip if removed is not None: pred.skip -= 1 return removed class _TailNode(_SkipNode): class _TailItem(object): def __lt__(self, other): return False def __le__(self, other): return False def __init__(self): super().__init__(_TailNode._TailItem(), None, None, 0) def __contains__(self, item): return False def insert(self, item, prob): return (self, 1) def remove(self, item): return None class _HeadNode(_SkipNode): FIELD_WIDTH = 4 def __init__(self, down, right, skip=1): super().__init__(None, down, right, skip) def __str__(self): below = str(self.down) level = " -" + " " * (_HeadNode.FIELD_WIDTH + 4) * (self.skip - 1) while not isinstance(self.right, _TailNode): self = self.right level += ("> {{:>{}}} -".format(_HeadNode.FIELD_WIDTH) .format(repr(self.item)) + " " * (_HeadNode.FIELD_WIDTH + 4) * (self.skip - 1)) return level + "> \n" + below class _SkipIter(object): def __init__(self, start): self.current = start.right def __iter__(self): return self def __next__(self): if isinstance(self.current, _TailNode): raise StopIteration() item = self.current.item self.current = self.current.right return item[/mw_shl_code] 题目6: [mw_shl_code=python,true]def reverse(string): strlist = list(string) first = 0 last = len(strlist) - 1 while first < last: strlist[first], strlist[last] = strlist[last], strlist[first] first += 1 last -= 1 result = '' for char in strlist: result += char return result[/mw_shl_code] 题目7: [mw_shl_code=python,true]def question7(): profit = int(input('Please enter the profit: ')) cases = [1000000, 600000, 400000, 200000, 100000, 0] interest = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1] reward = 0 for i in range(6): if profit > cases: reward += (profit - cases) * interest profit = cases print(reward)[/mw_shl_code] 题目8: [mw_shl_code=python,true]def question8(): return helperForQ8(1) def helperForQ8(day): if day == 10: return 1 else: return helperForQ8(day + 1) * 2[/mw_shl_code] 题目9: [mw_shl_code=python,true]def question9(): numlist = [] cont = 'y' while cont == 'y': num = input('Please enter a number: ') numlist.append(float(num)) cont = input('Continue to enter numbers? (please enter "y" or "n"): ') maxindex = numlist.index(max(numlist)) numlist[maxindex], numlist[0] = numlist[0], numlist[maxindex] minindex = numlist.index(min(numlist)) numlist[minindex], numlist[-1] = numlist[-1], numlist[minindex] return numlist[/mw_shl_code] 题目10: 能8能被逆向解析什么滴咱完全8知道啊!~总之先来试试而已...OTZ... 反正就是输入密码然后加密文件...吧....?~咱理解题目能力有限..._(:з」∠)_... 只有这题是用java来写滴...因为咱8知道python肿么输出文件了啦!~@@8!! java语法其实咱都快忘光了..._(:з」∠)_...下学期要肿么破啊喂.... [mw_shl_code=java,true]import java.awt.*; import hsa.Console; import hsa.*; public class Crytpo { static Console c; // Main Program public static void main (String[] args) { c = new Console (); c.println ("Please enter a key: "); String key = c.readLine (); c.println ("Please enter the file name: "); String fileName = c.readLine (); Vigenere x = new Vigenere (key); String y = x.encrypt (fileName); } } class Vigenere { protected String key; public Vigenere (String k) { key = k; } public String encrypt (String fileName) { int pnt = fileName.indexOf ("."); String ciphafile; String line; String cipha; if (pnt != -1) ciphafile = fileName.substring (0, pnt) + ".cyp"; else ciphafile = fileName + ".cyp"; TextInputFile input = new TextInputFile (fileName); TextOutputFile output = new TextOutputFile (ciphafile); while (!input.eof ()) { line = input.readLine (); cipha = encryptLine (line); output.println (cipha); } return ciphafile; } public String encryptLine (String line) { String enLine = ""; char x; char y; int i = 0; while (i < line.length ()) { x = line.charAt (i); if (x >= ' ' && x <= '~') { y = (char) (key.charAt (i % key.length ()) - ' '); x = (char) (x + y); if (x > '~') x = (char) (x - '~' + ' ' - 1); } enLine = enLine + x; i++; } return enLine; } } [/mw_shl_code] 完毕!~艾玛咱居然10题都做了!~ 这不科学啊啊啊啊啊!!!~#33t 正确率目测一般就是了~( ̄▽ ̄")~ 看咱从预订滴3题变成了10题都做滴份上求!给!糖!滴说~~~!23!
查看回复

本帖最后由

作者:虹why
[i=s] 本帖最后由 虹why 于 2013-4-23 22:10 编辑 参与人ID(UID): 虹why(6964) 参与类型: A 编程题目类 答案:第一题: #include<stdio.h> void main() { int i,j,sum; for(i=2;i<1000;i++) { sum=0; for(j=1;j<i;j++) if(i%j==0) sum+=j; if(sum==i) printf("%d\n",i); } } 第二题: #include<stdio.h> void main() { int i; float h=100,sum=0; sum=sum+h; h=h/2; for(i=1;i<10;i++) { sum=sum+2*h; h=h/2; } printf("第10次落地时,共经过%.3f米;\n第10次反弹高度为%f\n",sum,h); } 第三题: #include<stdio.h> char fun(int n) { switch(n) { case 0:return 'x';break; case 1:return 'y';break; case 2:return 'z';break; } } void main() { int a,b,c; for(a=0;a<3;a++) if(a!=0) for(b=0;b<3;b++) if(b!=a) for(c=0;c<3;c++) if(c!=0&&c!=2&&c!=b&&c!=a) printf("甲队的a对战乙队的%c\n甲队的b对战乙队的%c\n甲队的c对战乙队的%c\n",fun(a),fun(b),fun(c)); } 第四题: #include<stdio.h> void main() { int nl[5],i; nl[0]=10; for(i=1;i<5;i++) nl=nl[i-1]+2; printf("第五个人年龄为%d\n",nl[4]); } 第五题: 占时空着,我讨厌指针和链表。。。 第六题: #include<string.h> #include<stdio.h> void main() { char s[250],temp; int i,c; printf("请输入字符串:\n"); scanf("%s",s); c=strlen(s); for(i=0;i<c/2;i++) { temp=s; s=s[c-i-1]; s[c-i-1]=temp; } printf("反过来后的字符串是:%s\n",s); } 第七题: #include<stdio.h> void main() { float money,sum=0; printf("请输入这个月的利润:\n"); scanf("%f",&money); if(money<=100000) sum+=money*0.1; else { sum+=100000*0.1; if(money<=200000) sum+=(money-100000)*0.075; else { sum+=100000*0.075; if(money<=400000) sum+=(money-200000)*0.05; else { sum+=200000*0.05; if(money<=600000) sum+=(money-400000)*0.03; else { sum+=200000*0.03; if(money<1000000) sum+=(money-600000)*0.015; else { sum+=400000*0.015; if(money>1000000) sum+=(money-1000000)*0.01; } } } } } printf("这个月的奖金是:%f\n",sum); } 第八题: #include<stdio.h> void main() { int sum=1,i; for(i=1;i<10;i++) sum=(sum+1)*2; printf("桃子个数是:%d\n",sum); } 第九题: #include<stdio.h> void main() { float m[300],temp; int n,i,max=0,min=0; printf("请输入数组元素个数:\n"); scanf("%d",&n); printf("请输入元素:\n"); for(i=0;i<n;i++) { scanf("%f",&m); if(m>m[max]) max=i; if(m<m[min]) min=i; } temp=m[max]; m[max]=m[0]; m[0]=temp; temp=m[min]; m[min]=m[n-1]; m[n-1]=temp; printf("调整后的结果为:\n"); for(i=0;i<n;i++) printf("%.3f\n",m); } 第十题: 也暂时空着。。密码加密,我只看过理论知识。。。。
查看回复

本帖最后由

作者:夏尘安
[i=s] 本帖最后由 夏尘安 于 2013-4-26 17:18 编辑 参与人ID(UID): 夏尘安(249866) 参与类型: A 编程题目类 / 答案:........ 1.题目:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程 找出1000以内的所有完数。 #include<stdio.h> #include<iostream.h> void main() { int i,j,sum; for(i=1;i<=1000;i++) { sum=0; for(j=1;j<i;j++) { if(i%j==0) sum+=j; } if(sum==i) cout<<i<<endl; } } 答案:6 28 496 2.题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高? #include<stdio.h> #include<iostream.h> void main() { float high=100,sum=0; int i; for(i=0;i<10;i++) { sum=sum+2*high; high=high/2.0; cout<<"sum="<<sum-100<<",high="<<high<<endl; } } 答案:sum=299.609,high=0.0976563 3.题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。 #include<stdio.h> #include<iostream.h> void main() { char a,b,c; int flag=0; for(a='x';a<='z';a++) { if(a=='x') a++; for(b='x';b<'z';b++) { for(c='x';c<'z';c++) { if((c!='x'||c!='z')&&(c!=b)&&(c!=a)&&(b!=a)) {flag=1;break;} } if(flag==1) break; } if(flag==1) break; } cout<<"a vs "<<a<<"\nb vs "<<b<<"\nc vs "<<c<<endl; } 答案: a-z,b-x,c-y 4.题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大? #include<stdio.h> #include<iostream.h> void main() { int i,age[5]={10}; for(i=1;i<5;i++) { age=age[i-1]+2; } cout<<"age[4]="<<age[4]<<endl; } 答案:18 5.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? #include<stdio.h> #include<iostream.h> #include<stdlib.h> typedef struct node { int data; struct node *next; }LNode,*LinkList; LinkList Creat_LinkList() { LinkList L=NULL; LNode *s; int x; do { scanf("%d",&x); s=(LNode *)malloc(sizeof(LNode)); s->data=x; s->next=L;L=s; }while(getchar()!='\n'); return L; } void main() { LNode *s,*start; LinkList flag=NULL,prior; int swap,s_flag; cout<<"please enter the numbers:"<<endl; start=Creat_LinkList(); s=start; prior=start; while(s->next!=NULL) {swap=0; s_flag=0; while(s->next!=flag) { if((s->data)>(s->next->data)) { if(s==start) { start=s->next; s->next=s->next->next; start->next=s; s_flag=1; } else { prior->next=s->next; s->next=s->next->next; prior->next->next=s; s=prior->next; s_flag=0; } swap=1; } else s_flag=0; if(s_flag==1) { s=s; prior=start; } else { prior=s; s=s->next; } } flag=s; s=start; prior=s; if(swap==0) break; } s=start; while(s!=NULL) { cout<<s->data<<" "; s=s->next; } cout<<endl; } 采用冒泡排序,随意输入整数值即可从小到大排序。 单纯喜欢“冒泡”这个名字! 至少比较稳定虽然时间性能什么的不太好~ 不知道用链表实现会不会很奇怪!~ 6.编写反转字符串的程序,要求优化速度、优化空间。 #include<stdio.h> #include<iostream.h> #include<string.h> void main() { char array[200],temp; int i,len; printf("please enter a string(don't beyond 200):\n"); gets(array); len=strlen(array); for(i=0;i<len/2;i++) { temp=array; array=array[len-1-i]; array[len-1-i]=temp; } cout<<"after reversal the string is:\n"<<array<<endl; } 7.题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润,求应发放奖金总数 #include<stdio.h> #include<iostream.h> #include<string.h> void main() { int I; double bonus=0; printf("please enter the profit(yuan) that month:\n"); scanf("%d",&I); if(I<100000||I==100000) bonus=0.1 *I; else if(100000<I&&(I<200000||I==200000)) bonus=0.1 *100000+0.075*(I-100000); else if(200000<I&&(I<400000||I==400000)) bonus=0.1 *100000+0.075*100000+0.05*(I-200000); else if(400000<I&&(I<600000||I==600000)) bonus=0.1 *100000+0.075*100000+0.05*200000+0.03*(I-400000); else if(600000<I&&(I<1000000||I==1000000)) bonus=0.1 *100000+0.075*100000+0.05*200000+0.03*200000+0.015*(I-600000); else if(I>1000000) bonus=0.1*100000+0.075*100000+0.05*200000+0.03*200000+0.015*400000+0.01*(I-1000000); cout<<"total bonus is "<<bonus<<"(yuan)"<<endl; } 8.题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下 的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。 #include<stdio.h> #include<iostream.h> #include<string.h> int reverse_eat(int n) { int left; left=(n+1)*2; return left; } void main() { int n=1; for(int i=0;i<10;i++) { n=reverse_eat(n);} cout<<"the total num of peaches is "<<n<<endl; } 答案:3070 9.题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。 #include<stdio.h> #include<iostream.h> #include<stdlib.h> void main() { int array[200],n=0,x,i,max,min,maxnum,minnum; cout<<"please enter the numbers(don't beyond 200 nums):"<<endl; do { scanf("%d",&x); array[n++]=x; }while(getchar()!='\n'); cout<<"total num is "<<n<<endl; max=array[0]; maxnum=0; for(i=1;i<n;i++) { if(array>max) {max=array;maxnum=i;} } array[maxnum]=array[0]; array[0]=max; min=array[0]; minnum=0; for(i=1;i<n;i++) { if(array<min) { min=array;minnum=i;} } array[minnum]=array[n-1]; array[n-1]=min; cout<<"after exchange:\n"; for(i=0;i<n;i++) cout<<array<<" "; cout<<endl; } 10.选作题:设计并实现一个密码加密算法,要求加密后的密文不能依据程序而进行逆向解析(尽可能的不能被解析)
查看回复

本帖最后由

作者:你说的a不对
[i=s] 本帖最后由 你说的a不对 于 2013-4-24 22:51 编辑 参与人ID(UID): 你说的a不对(109463) 参与类型: A 编程题目类 答案:(用 java写的) 第2题—— public class motionOfBall { public static void main(String[] args){ double highest =100 , sum =100; for (int i=1;i<=10;i++) { highest = highest*0.5; sum = sum + highest*2;// total traveled distance right before next jump // System.out.println("after "+i+ " bounce , the ball can jump "+highest+"m."); } System.out.println("after 10 bounce , the ball can jump to "+highest+"m."); sum = sum - highest*2; System.out.print("It went through "+sum+"m in all"); } } 第3题—— public class gamePlayer { public static void main(String[] args){ //arragement int[][] arr= {{1,1,1}, {1,1,1}, {1,1,1}}; arr[2][0]= 0; arr[2][2]= 0;//condition that we know arr[0][0]= 0; for(int i=0;i<3;i++){ int sum=0,x=0; for(int j=0;j<3;j++){ sum=sum+arr[j]; if (arr[j]==1) x=j; } if (sum==1) { for(int t=0;t<3;t++) { if(t!=i) arr[t][x]=0; } } } // check each row for(int j=0;j<3;j++){ int sum=0,x=0; for(int i=0;i<3;i++){ sum=sum+arr[j]; if (arr[j]==1) x=i; } if (sum==1) { for(int t=0;t<3;t++) { if(t!=j) arr[x][t]=0; } } } // check each column System.out.println(" x y z"); System.out.print("a "); for(int j=0;j<3;j++){ System.out.print(arr[0][j]+" "); } System.out.print("\n"); System.out.print("b "); for(int j=0;j<3;j++){ System.out.print(arr[1][j]+" "); } System.out.print("\n"); System.out.print("c "); for(int j=0;j<3;j++){ System.out.print(arr[2][j]+" "); } /* only print the matrix for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ System.out.print(arr[j]+" "); } System.out.print("\n"); }*/ } } 第7题—— import java.util.Scanner; public class computeBonus { public static void main(String[] args){ Scanner inputNum = new Scanner(System.in); System.out.print("Enter the profit (yuan): "); double I=inputNum.nextDouble(); double bonus=0; if(I<=100000) bonus=I*0.1; else if (I<=200000) bonus=100000*0.1+(I-100000)*0.075; else if (I<=400000) bonus=100000*0.1+100000*0.075+(I-200000)*0.05; else if(I<=600000) bonus=100000*0.1+100000*0.075+200000*0.05+(I-400000)*0.03; else if(I<=1000000) bonus=100000*0.1+100000*0.075+200000*0.05+200000*0.03+(I-60)*0.015; else bonus=100000*0.1+100000*0.075+200000*0.05+200000*0.03+400000*0.015+(I-1000000)*0.01; System.out.println("The bonus is "+(int)(bonus*100)/100.0 + "(yuan)"); } } 第9题 import java.util.*; public class arrayHandle { static Scanner input=new Scanner(System.in); public static void main(String[] args){ int numberOfElements; System.out.print("How many numbers you plan to input?"); numberOfElements=input.nextInt(); System.out.println("Now enter your numbers!"); dealNum(numberOfElements); } public static void dealNum(int num) { double[] myList = new double[num]; for(int i=0;i<num;i++) myList=input.nextDouble(); double maxNum=myList[0],minNum=myList[0]; System.out.println("The array you entered is: "); for(int i=0;i<num;i++){ System.out.print(myList+" "); if (myList>maxNum) maxNum=myList; if (myList<minNum) minNum=myList; } //System.out.print("In this array,the biggest one is "+maxNum+", and the smallest is "+minNum); myList[0]=maxNum; myList[num-1]=minNum; System.out.println("\n"+"Your new array is:"); for (int i=0;i<num;i++) System.out.print(myList+" "); } }
查看回复

其实我好懒

作者:linyu0077
- -啊,其实我好懒,不过尽然发现好多题目写过的。。。 ID:linyu0077 题目除了5 6.。。太麻烦了不想再去找了。。。 #include<stdio.h> int main() { float length=100,sum=0; int i; for(i=1;i<=10;i++) { sum+=length; length=length/2; } printf("%f\n",sum); return 0; } //2 #include<stdio.h> int main() { int m,n=1; for(m=1;m<1000;m=m+n) { printf("%d ",m); n++; } printf("\n"); return 0; } //1 #include<stdio.h> int main() { char i,j,k; for(i='x';i<='z';i++) for(j='x';j<='z';j++) { if(i!=j) for(k='x';k<='z';k++) { if(i!=k&&j!=k) { if(i!='x'&&k!='x'&&k!='z') printf("order is : a--%c\tb--%c\tc--%c\t\n",i,j,k); } } } return 0; } //3 #include<stdio.h> int main() { int n=10; n+=2; n+=2; n+=2; n+=2; printf("%d\n",n); } //4 #include<stdio.h> int main() { long int i; int bonus1,bonus2,bonus4,bonus6,bonus10,bonus; scanf_s("%ld",&i); bonus1=100000*0.1; bonus2=bonus1+100000*0.75; bonus4=bonus2+200000*0.5; bonus6=bonus4+200000*0.3; bonus10=bonus6+400000*0.15; if(i<=100000) bonus=i*0.1; else if(i<=200000) bonus=bonus1+(i-100000)*0.075; else if(i<=400000) bonus=bonus2+(i-200000)*0.05; else if(i<=600000) bonus=bonus4+(i-400000)*0.03; else if(i<=1000000) bonus=bonus6+(i-600000)*0.015; else bonus=bonus10+(i-1000000)*0.01; printf("bonus=%d\n",bonus); return 0; } //7 #include<stdio.h> int main() { int sum=1; int judge; for(judge=1;judge<=10;judge++) { sum=(sum+1)*2; } printf("%d\n",sum/2+1); return 0; } //8 #include<stdio.h> int main() { int area[10000+1]={0}; int max=0,min; int max_number=1,min_number=1; int i=1; scanf("%d",&area); i++; max=min=area[1]; while(scanf_s("%d",&area)) { i++; if(max < area) {max= area;max_number=i;} if(min > area) {min= area;min_number=1;} } int middle; middle=area[1]; area[1]=area[max_number]; area[max_number]=middle; middle=area; area=area[min_number]; area[min_number]=middle; for(min=1;min<=i;i++) printf("%d",area[min]); return 0; } //9 题号在答案下面0 0 亲
查看回复
上一页
下一页
0%
站点地图友情链接:
喵宅苑
喵空间社区程序
喵宅苑 静态版
宅喵RPG地图编辑器
络合兔
Lanzainc
技术宅
小五四博客
莉可POI
Mithril.js
枫の主题社
Project1
午后少年
机智库
七濑胡桃
xiuno
幻想の日常
魂研社
Nothentai
0xffff
欲望之花
泽泽社长
淀粉月刊
HAYOU