有爱,有技术,有你^_^)y
╱人◕‿‿◕人╲订下契约(注册新用户)

合作站点账号登陆

QQ登录

只需一步,快速开始

快捷导航
查看: 3666|回复: 31
收起左侧

[活动] 参与活动贴【禁水】

 关闭 [复制链接]

签到天数: 3 天

连续签到: 1 天

[LV.2]偶尔看看I

41

主题

60

好友

2万

积分

第一章

守望者

积分
21763
发表于 2013-4-15 21:28:27 | 显示全部楼层 |阅读模式

╱人◕‿‿◕人╲定下契约

您需要 登录 才可以下载或查看,没有账号?╱人◕‿‿◕人╲订下契约(注册新用户)

x
不晓得这是干什么的请移步https://www.gn00.com/forum.php?mod=viewthread&tid=279549&page=1&extra=#pid15711393 先看完再来回帖

否则,你懂得   扣除20宅币+5宅贡献的说

本帖已经设置本人可见,请放心回帖,回帖格式举例:
                     参与人ID(UID): Mr_Alex(293988) ——团体参与的请把所有人列出来
                     参与类型: A 编程题目类 / B 应用项目类
                     答案:........

在本帖回帖后请移步 https://www.gn00.com/forum.php?mod=viewthread&tid=279549&page=1&extra=#pid15711393 贴子点击页面的参与,然后将你的本帖回帖的楼层填写进去提交,否则视为未参与

编程类:
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日前后公布接收源码的邮箱,敬请关注。


小提示: 你可以先在本帖回帖占楼,然后去报名帖报名,为了将来评分方便,请在报名的时候贴上你在本贴回帖的楼层。谢谢合作!  如果你在本帖已经占楼,请务必去报名并在活动结束前来本帖完善编辑答题,否则将视为水贴。在本帖水是会被扣分的撒
   



2013.05.15日: 现公布递交应用类答案的邮箱 [email protected] ,请选择应用类题目的参与者及时递交答案。接受答案截止日期2013年6月15日。


















评分

参与人数 4宅魂 +4 宅币 +10 活跃 +1 收起 理由
PC1500 + 1 + 2 →_→第一题啊喂!(#`O′) 因子不算本身吧.
天堂at人间 + 2 + 5 话说报名没有填写楼层我要怎么办。。。.
繁尘、离梦 + 1 + 3 求验证代码发几多糖- , -
terry182 + 1 混淡第一題是怎麼回事,因子不算自身是嗎.

查看全部评分

如果有来生,要做一棵树,站成永恒,没有悲欢的姿势。一半在土里安详,一半在风里飞扬,一半洒落阴凉,一半沐浴阳光,非常沉默非常骄傲,从不依靠从不寻找。
回复

使用道具 举报

该用户从未签到

25

主题

59

好友

8779

积分

序章

积分
8779
发表于 2013-4-15 23:50:55 | 显示全部楼层
本帖最后由 terry182 于 2013-4-21 21:22 编辑

参与人ID(UID): terry182(293988)
参与类型: A 编程题目类
答案:
[fold=第一題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  1.cpp
*
*    Description:  GN00活動 1. 完數
*
*        Version:  1.0
*        Created:  2013/4/15 星期一 下午 10:34:01
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int list[11]={2,3,5,7,11,13,17,19,23,29,31};
int divide(int a)
{  if (a==1)
                return 0;
  int record=a;
  int time=0,temp=0;
  int ans=1;
        while (a!=1 && temp < 11)
        { while (a%list[temp]==0)
                { time++;
                  a=a/list[temp];}
          int t=list[temp];
           for (int i=0;i<time;i++)
                        t*=list[temp];
          ans *=(t-1)/(list[temp]-1);
          temp++;time=0;
        }
        if (ans==0)
                return 1;
        return ans-record;
}


int main()
{ int count=0;
  for (int i=1;i<1000;i++)
        if (divide(i)==i)
                cout << ++count << ":" << i << endl;
  return 0;
}
[/mw_shl_code][/fold]
[fold=第二題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  2.cpp
*
*    Description:  gn00 一球?100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地?,共??多少米?第10次反?多高?
*
*        Version:  1.0
*        Created:  2013/4/15 星期一 下午 10:41:31
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int main()
{ double n=1;
  double total=0,last=0;
        for (int i=0;i<10;i++)
                   n*=0.5;
        total=100*(1-n)/0.5;
        last=100*n/0.5;
  cout << "total:" << total << endl;
  cout << "last :" << last << endl;
  return 0;
}
[/mw_shl_code][/fold]
[fold=第三題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  3.cpp
*
*    Description:  gn00 3.
*
*        Version:  1.0
*        Created:  2013/4/15 星期一 下午 10:46:07
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct people {
        char id;
        char d;
        vector<int> no;
};

int compare(people a,people b)
{ return a.no.size() > b.no.size();}

int c(people a,people b)
{ return a.id < b.id;}

int main()
{ people fight[3];
  fight[0].no.push_back('x');fight[0].id='a';
  fight[1].id='b';
  fight[2].no.push_back('x');  fight[2].no.push_back('z');fight[2].id='c';
  
  sort(fight,fight+3,compare);
  for (int i=0;i<3;i++)
  { for (int j=0;j<3;j++)
        { for (int x=0;x<fight.no.size();x++)
                if (fight.no[x]!=x+'x')
                {         fight.d=x+'x';
                        fight[(i+1)%3].no.push_back(x+'x');
                        fight[(i+2)%3].no.push_back(x+'x');
                   x=fight.no.size();
                }
        }
  }
  sort(fight,fight+3,c);
  for (int i=0;i<3;i++)
  cout << fight.id << " vs " <<fight.d << endl;
  return 0;
}
[/mw_shl_code][/fold]
[fold=第四題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  4.cpp
*
*    Description:  gn00 4
*
*        Version:  1.0
*        Created:  2013/4/15 星期一 下午 11:07:59
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int main()
{ cout << 10+2*(5-1) << endl;
  return 0;
}
[/mw_shl_code][/fold]
[fold=第五題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  5.cpp
*
*    Description:  
*
*        Version:  1.0
*        Created:  2013/4/15 星期一 下午 11:10:13
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
struct node{
        int value;
        node *next;
};

void bubble_sort(node *start,int size)
{ node *current=start;
        for (int i=0;i<size;i++)
        { node *temp = current -> next;
          for (int j=i;j<size;j++)
                { if (temp -> value < current-> value)
                        swap(temp->value,current->value);
                }
          current = current -> next;
        }
}

int main()
{ int n;
    cout << "請輸入鏈表的大小:" ;
        cin >> n; cout << endl;
    cout << "請輸入數據,注意以空格隔開:";
  node *start=new node;
  node *current,*input;
   cin >> start -> value;
   current = start;
          for (int i=1;i<n;i++)
        { input = new node;
          cin >> input->value;
          current -> next = input;
          current = current -> next;
        }
         cout << endl;
        bubble_sort(start,n);
        cout <<" 排序後:" ;
  current = start;        
  for (int i=0;i<n;i++)
        { cout << current -> value << " ";
          current =current -> next;
        }
  cout << endl;
return 0;}
[/mw_shl_code][/fold]
[fold=第六題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  6.cpp
*
*    Description:  gn00 6
*
*        Version:  1.0
*     Created:  2013/4/18 星期四 下午 06:00:11
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int main()
{ string s;
        getline(cin,s);
  for (int i=0;i<(s.length()+s.length()%2)/2;i++)
          swap(s,s[s.length()-1-i]);
        cout << s << endl;
return 0;
}
[/mw_shl_code][/fold]
[fold=第七題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  7.cpp
*
*    Description:  gn00
*
*        Version:  1.0
*        Created:  2013/4/19 星期五 下午 08:16:51
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int main()
{ int a[6]={0};
  long long int total;
          cin >> total;
  if (total > 1000000)
  { a[5]=total-1000000;
    total-=a[5];
  }
  if (total > 600000)
  { a[4]=total-600000;
    total-=a[4];
  }
  if (total > 400000)
  {  a[3]=total-400000;
    total-=a[3];
  }
  if (total > 200000)
  { a[2]=total-200000;
    total-=a[2];
  }
    if (total > 100000)
  { a[1]=total-100000;
    total-=a[1];
  }
    a[0]=total;
   long double ans=(long double)a[0]*0.1+(long double)a[1]*0.075;
   ans+=(long double)a[2]*0.05+(long double)a[3]*0.03;
   ans+=(long double)a[4]*0.015+(long double)a[3]*0.01;
   cout << ans << endl;
return 0;}
[/mw_shl_code][/fold]
[fold=第八題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  8.cpp
*
*    Description:  
*
*        Version:  1.0
*        Created:  Saturday, 20/04/2013 17:33:52
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int main()
{ int a=1;
        for (int i=0;i<9;i++)
        { a=(a+1)*2;}
cout << a << endl;
return 0;
}
[/mw_shl_code][/fold]
[fold=第九題][mw_shl_code=cpp,true]/*
* =====================================================================================
*
*       Filename:  9.cpp
*
*    Description:  gn00
*
*        Version:  1.0
*        Created:  Saturday, 20/04/2013 17:37:15
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Terry Cheong. (terry182)
*   Organization:  
*
* =====================================================================================
*/

#include <iostream>
using namespace std;
int main()
{ int n;
        cout << "請輸入數組大小:" ;cin >> n;
        int a[n];
        cout << "請輸入數組:";
        int max=0,min=0;
        for (int i=0;i<n;i++)
        { cin >> a;
          max= a[max] < a? i : max;
          min= a[min] > a? i : min;}
        if (min == 0 && max==n-1 || min==n-1 && max==0)
           { swap(a[max],a[0]);}
        else swap(a[min],a[n-1]),swap(a[max],a[0]);
        cout << "處理後:";
        for (int i=0;i<n;i++)
        { cout << a << " ";}
        cout << endl;
  return 0;
}
        
[/mw_shl_code][/fold]
第十題還在想。

gn00.rar

5.13 KB, 下载次数: 0, 下载积分: 宅币 -50 枚, 活跃 1 ℃

点评

感谢参与,请及时回来编辑你的帖子哟~  发表于 2013-4-20 09:02
欢迎参与~~  发表于 2013-4-16 08:27
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

30

主题

127

好友

2万

积分

技术宅认证程序员

重度中二患者

积分
28325
发表于 2013-4-16 14:53:50 | 显示全部楼层
本帖最后由 foodszhu 于 2013-4-22 13:36 编辑

参与人ID(UID):foodszhu(205569)
参与类型: A 编程题目类
答案:该写的都写到代码注释里了。。。没输入。。。。测试的话自己加raw_input好啦。。。
第十题没写。。。原因这东西想认真做个吧。。。正好这学期学密码学。。。实在不行贴个RSA上来好不。。
[mw_shl_code=python,true]#!/usr/bin/env python
#-*-coding:utf-8 -*-

import sys
import hashlib
import operator

##1.暴力搜。。。。
print [x for x in range(2,1000) if sum([i for i in range(1, x) if x % i == 0]) == x]
print

##2.应该是这样吧。。。物理无力啊。。。。
s = [100 * 0.5 ** n for n in range(1, 11)]
print 0.5 * s[9], sum(2 * s) - 50
print

##3.这种题反而有种无从下手的感觉。。。写个通用一点的吧。类似高斯消元。。。不过没有枚举自由变元。。汗。。。这种一眼看出答案就略蛋疼。。。
d = [[1 for row in range(3)] for col in range(3)]
d[0][0], d[2][0], d[2][2] = 0, 0, 0
for t in range(3):
    for i in range(3):
        if sum(d) == 1:
            for j in range(3):
                if d[j] == 1:
                    for k in range(3):
                        if k != i:
                            d[k][j] = 0
#如果有唯一解应该是每行每列有且仅有一个
f = {}
for i, x in enumerate("abc"):
    for j, y in enumerate("xyz"):
        if d[j] == 1:
            f[x] = y
print f
print

##4.没看懂这题要干什么啊。。。函数嵌套?
f = lambda c : c + 2
print f(f(f(f(10))))
print

##5.还得自己实现链表么。。。。算了。。。大概就两种吧。。。链表快排。。。比归并唯一好的地方在于省空间。。。如果用归并不如直接存数组。。。

class node(object):
    def __init__(self, val):
        self.val = val
        self.last = self

    def add(self, val):
        self.last.next  = node(val)
        self.last = self.last.next

    def qsort(self, last = 'tail'):
        head = self
        if last is 'tail':
            try:
                last = self.last.next
            except:
                last = None
        if self is last:
            return
        ##last指向末尾的下一位
        split_node = head
        iter_node = split_node.next
        split_val = head
        while(iter_node is not last):
            if iter_node.val < split_val.val:
                iter_node.val, split_node.val = split_node.val, iter_node.val
                if split_node.val == split_val.val:
                    split_val = iter_node
                    #跟踪分割节点的位置
                split_node = split_node.next
            try:
                iter_node = iter_node.next
            except:
                break
        split_val.val, split_node.val = split_node.val, split_val.val
        #让分割节点处于自己的位置
        head.qsort(split_node)
        try:
            split_node.next.qsort(last)
        except:pass

    def addList(self, la):
        for i in la:
            self.add(i)

    def printf(self):
        i = self
        while i is not self.last:
            print i.val,
            i = i.next
        print i.val


a = node(4)
a.addList([7, 8, 1, 5, 3, 9, 6])
a.qsort()
a.printf()
print

##6.python原生写这东西非常简单啊。。。而且保证效率高。。。换成其他语言,反转字串这东西难道是要考虑用不用临时变量,还有存储字串长度的问题么?
##  如果像C没有存储字串长度,肯定需要遍历一遍
a = "hello world"
print a[::-1]
print

##7.好不想写.....
#I = int(raw_input())
I = 13.75
T = [0.1, 0.075, 0.05, 0.03, 0.015, 0.01]
U = [0, 10, 20, 40, 60, 100, sys.maxint]
S = 0
for i, u in enumerate(U):
    if I > u:
        if i > 0:
            S += T[i - 1] * (U - U[i - 1])
    else:
        S += (I - U[i-i]) * T[i - 1]
        break
print S
print

##8.这不是大一时候的题目么。。。正着反者都可以啊。。
f = lambda a : 2 * a + 2
a = 1
for i in range(9):
    a = f(a)
print a
print

##9.这这这。。。如果没要求了反而有种不安的感觉啊。。。。
a = [3, 6, 2, 8, 4, 1, 9, 5, 7]
d = {y : x for x, y in enumerate(a)}
lena, maxa, mina =len(a), max(a), min(a)
a[d[maxa]], a[0], a[d[mina]], a[lena - 1] = a[0], a[d[maxa]], a[lena - 1], a[d[mina]]
print a
print
##这样做看起来简单的但所花费的空间反而大了。。。其实老老实实遍历一遍什么事都没有啊。。。
10.#密码加密的话就啥话都不说了。。。单向哈希多次肯定比较容易实现且难以破解。。。。
def encrypt(username, password, createtime = '19910101', itertimes = 1000):
    username = hashlib.md5(username).hexdigest()
    password = hashlib.md5(password).hexdigest()
    salt = hashlib.md5(createtime).hexdigest()
    plain = username + password + createtime
    def U():
        u = username
        for k in xrange(itertimes):
            u = hashlib.sha1(str(int(plain, 16) ^ int(createtime + u, 16)) + password).hexdigest()
            yield int(u, 16)
    return str(hex(reduce(operator.xor, U())))[2:-1]
a = encrypt('foodszhu', 'zhang')
print a
[/mw_shl_code]




评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 参与奖励,等结果出来还有其他奖励呢~.

查看全部评分

等死星人
回复 支持 反对

使用道具 举报

签到天数: 1 天

连续签到: 1 天

[LV.1]初来乍到

24

主题

91

好友

3501

积分

天然呆

Tschuess!

积分
3501
发表于 2013-4-16 20:20:15 | 显示全部楼层
参与人ID(UID):Trozamy(318026)
参与类型:B 应用项目类【真是不怕死啊
答案:........

这里是占坑的节奏?

点评

期末考试= =卧槽  发表于 2013-6-7 09:52
没开始撸╮( ̄▽ ̄")╭  发表于 2013-6-7 09:52
去死!去死!去死!去死!去死!
回复 支持 反对

使用道具 举报

该用户从未签到

3

主题

2

好友

4933

积分

序章

积分
4933
发表于 2013-4-16 22:46:32 | 显示全部楼层
本帖最后由 PC1500 于 2013-6-10 23:16 编辑

话说拖延症什么的- -咳咳~慢慢来~
参与人ID(UID):PC1500(416880)
参与类型: A 编程题目类
答案:1.
[mw_shl_code=java,true]public class Number1
{
        public static void main(String args[])
        {
                int i;
                int j;
                int k;
                int m;
                for(m=1;m<=1000;m++)
                {
                        k=0;
                        for(i=1;i<m;i++)
                        {
                                j=m%i;
                                if(j==0)
                                {
                                        k=k+i;
                                }
                        }
                        if(k==m)
                        {
                                System.out.println(m);
                        }
                }
        }
}[/mw_shl_code]

6
28
496

还是第一题【因子什么的算自己本身吗???真因子数吧】
[mw_shl_code=java,true]public class Number1
{
        public static void main(String args[])
        {
                int i;
                int j;
                int k;
                int m;
                for(m=1;m<=1000;m++)
                {
                        k=0;
                        for(i=1;i<=m;i++)
                        {
                                j=m%i;
                                if(j==0)
                                {
                                        k=k+i;
                                }
                        }
                        if(k==m)
                        {
                                System.out.println(m);
                        }
                }
        }
}[/mw_shl_code]
这个就只有1啊= =
2
[mw_shl_code=applescript,true]//一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
public class no2
{
public static void main(String[]args)
{
float m=100;
int i=0;
float s=100;
while(i<10)
{
m=tang(m);
s=s+m*2;
i++;
}
System.out.println("第十次落地经过"+s+"米,第十次反弹"+m/2+"米");
}
public static float tang(float x)
{
return x/2;
}
}[/mw_shl_code]

3.诶都,貌似是个很渣的算法╮( ̄▽ ̄")╭,有空再来改
[mw_shl_code=java,true]//两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。
//有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。

public class no3
{
public static void main(String[]args)
{
char a,b,c;
for(a='X';a<='Z';a++)
{
for(b='X';b<='Z';b++)
{
for(c='X';c<='Z';c++)
{
if(a!=b&&b!=c&&c!=a&&a!='X'&&c!='X'&&c!='Z')
{
System.out.println("A-"+a+" B-"+b+" C-"+c);
}
}
}
}

}
}[/mw_shl_code]

4.╮( ̄▽ ̄")╭ 无聊上来撸一题
[mw_shl_code=java,true]public class no4
{
        public static int[]a=new int[5];
        public static void sui(int i){
                a=a[i-1]+2;
                return ;
        }

        public static void main(String []args)
        {        
                int i;
                a[0]=10;
                for(i=1;i<5;i++){
                        sui(i);
                }
                System.out.println(a[4]);
               
                 
        }
        
}[/mw_shl_code]

点评

诶都!!!最近在撸课设╮( ̄▽ ̄")╭ 看到程序都头疼!这个差不多先放着吧,等我6.17结题答辩如果来的及的话再撸吧(其实是懒,咳咳)  发表于 2013-6-4 19:30
感谢参与,请及时回来编辑你的帖子哟~  发表于 2013-4-20 09:01
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

6

主题

19

好友

5098

积分

序章

积分
5098
发表于 2013-4-17 12:40:47 | 显示全部楼层
本帖最后由 骷骷马力梦魇 于 2013-5-2 20:36 编辑

参与人ID(UID): 骷骷马力梦魇(426619)
参与类型: A 编程题目类
答案:
1.
[mw_shl_code=c,true]#include<stdio.h>
int main()
{
int i,j,sum;
for(i=6;i<=1000;i++)
{
sum=0;  
for(j=1;j<=i/2;j++)
{
if(i%j==0)
sum=sum+j;
}
if(i==sum)
printf("%d\n",sum);
}
}[/mw_shl_code]
2.
[mw_shl_code=c,true]#include <stdio.h>
int main(void)
{
int i, n;
double distance, height;
height=100/2.0;
distance=height;
for(i=1;i<=10;i++)
{
distance=distance+height*2;
height=height/2.0;
}
height=height*2.0;
printf("distance = %.2f, height = %.2f\n", distance, height);
}[/mw_shl_code]
3.
[mw_shl_code=c,true]#include<stdio.h>
int main()
{
char i,j,k;//a说他不和x比,c说他不和x,z比
for(i='x';i<='z';i++)
for(j='x';j<='z';j++)
{
if(i!='x'&&i!=j)
for(k='x';k<='z';k++)
{
if(k!='x'&&k!='z'&&k!=i&&k!=j)
{
printf("a vs %c\nb vs %c\nc vs %c\n",i,j,k);
}
}
}
}[/mw_shl_code]
4.
[mw_shl_code=c,true]#include <stdio.h>
int main()
{
int a,b,c,d,e;
a=10;
b=a+2;
c=b+2;
d=c+2;
e=d+2;
printf("%d\n",e);
}[/mw_shl_code]

5.一直用冒泡排序,,,我只记得住这个
[mw_shl_code=cpp,true]#include<iostream>
#include<stdio.h>
using namespace std;
void sort(int a[],int n)
{
int i,j,t;
for(i=1;i<n;i++)
for(j=0;j<n-i;j++)
if(a[j]>a[j+1]){
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
int main()
{
int count,*a,i;
cin>>count;
a=new int [count];
for(i=0;i<count;i++)
cin>>a;

sort(a,count);
for(i=0;i<count;i++)
cout<<a<<" ";
cout<<endl;
return 0;
}[/mw_shl_code]
6.
[mw_shl_code=cpp,true]#include<stdio.h>
#include<string.h>
char* fun(const char* str)
{
char* tmp = new char[strlen(str) + 1];
strcpy(tmp,str);
char* q = tmp;
char* p = tmp + strlen(str) - 1;
while (p > tmp)
{
*p ^= *tmp;
*tmp ^= *p;
*p ^= *tmp;
--p;
++tmp;
}
return q;
}
int main()
{
char* str = "hello";
printf(str);
printf("\n");
char* str1 = fun(str);
printf(str1);
printf("\n");
}[/mw_shl_code]
7.
[mw_shl_code=c,true]#include <stdio.h>
int main()
{
double n,sum;
printf("请输入当月利润:");
scanf("%lf",&n);
if(0<=n<=100000)
sum=n*.1;
else if(n<=200000)
sum=100000*.1+(n-100000)*.05;
else if(n<=400000)
sum=100000*.1+100000*.075+(n-200000)*.05;
else if(n<=600000)
sum=100000*.1+100000*.075+200000*.05+(n-400000)*.03;
else if(n<=1000000)
sum=100000*.1+100000*.075+200000*.05+200000*.03+(n-600000)*.015;
else
sum=100000*.1+100000*.075+200000*.05+200000*.03+4000000*.015+(n-1000000);
printf("发放奖金为%.2lf\n",sum);
[/mw_shl_code]
8.
[mw_shl_code=c,true]#include <stdio.h>
int count(int n)
{
int y;
if(n==10)
y=1;
else y=(count(n+1)+1)*2;
return y;
}
int main()
{
printf("%d\n",count(1));
}[/mw_shl_code]
9.
[mw_shl_code=c,true]#include <stdio.h>
int main()
{
int i, max, min, n, t;
int a[10];
scanf("%d", &n);
for(i = 0; i < n; i++)
scanf("%d", &a);
min=max=0;
for(i=1;i<n;i++){
if(a<a[min])min=i;
if(a>a[max])max=i;
}
t=a[max]; a[max]=a[0]; a[0]=t;
t=a[min]; a[min]=a[n-1]; a[n-1]=t;
for(i = 0; i < n; i++)
printf("%d ", a);
printf("\n");
}[/mw_shl_code]

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 o(* ̄▽ ̄*)ブ 发糖

查看全部评分

签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

29

主题

54

好友

1万

积分

懒人

尔等还不速速跪下~

积分
11600
发表于 2013-4-17 14:57:27 | 显示全部楼层
本帖最后由 繁尘、离梦 于 2013-4-17 14:58 编辑

参与人ID:繁尘、离梦, 至于uid我都不知道哪去找- -
参与类型: A 编程题目类
10题解答见附件 花了1小时终于做完了
@Mr_Alex

10发编程题.rar

5.54 KB, 下载次数: 3, 下载积分: 宅币 -50 枚, 活跃 1 ℃

点评

大神触( ̄︶ ̄)y: 5.0 魂淡淡o( ̄ヘ ̄o#): 5.0
见第10楼嘛= =  发表于 2013-4-20 11:20
再次提醒,请编辑本贴然后直接把代码贴出来哟~  发表于 2013-4-20 09:01
大神触( ̄︶ ̄)y: 5 魂淡淡o( ̄ヘ ̄o#): 5
阿西吧 编程题请直接贴代码好么~  发表于 2013-4-17 20:14
别误会,这1小时指的是做尼玛的链表题,次哦。少了两个字  发表于 2013-4-17 16:38
笔迹流下的那瞬间 ,   沉睡了   ,   我在迷惘......
[url=http://d.hiphotos.baidu.com/album/s%3D1400%3Bq
回复 支持 反对

使用道具 举报

该用户从未签到

32

主题

79

好友

3万

积分

第二章

积分
30951
发表于 2013-4-17 15:44:00 | 显示全部楼层
本帖最后由 e_qing 于 2013-4-17 15:55 编辑

参与人ID(UID): e_qing(286644)
参与类型: A 编程题目类
1:
答案:6、28、496
代码:
[mw_shl_code=cpp,true]#include <iostream>
using namespace std;

int main()
{
        int sum, num, i;
        for (num=1; num<1001; num++)
        {
                sum = 0;
                for (i=1; i<num; i++)
                        if (num%i == 0)
                                sum += i;
                if (sum == num)
                        cout<<num<<endl;
        }
}[/mw_shl_code]
2:
答案:299.609375      0.09765625
代码:
[mw_shl_code=cpp,true]#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
        double sum = 100, h = 50;
        for (int i=1; i<10; i++)
        {
                sum += 2 * h;
                h /= 2;
        }
        printf("%.8f %.8f\n", sum, h);
}[/mw_shl_code]
3:
答案:a—z; b—x; c—y
代码:
[mw_shl_code=cpp,true]#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
        int a[4];
        int i, j, k;
        for (i=2; i<=3; i++)
        {
                a[1] = i;
                for (j=1; j<=3; j++)
                {
                        a[2] = j;
                        if (a[2] != a[1])
                                for (k=2; k<=2; k++)
                                {
                                        a[3] = k;
                                        if (a[3]!=a[2] && a[3]!=a[1])
                                        {
                                                cout<<"a-"<<char(i+'x'-1)<<endl;
                                                cout<<"b-"<<char(j+'x'-1)<<endl;
                                                cout<<"c-"<<char(k+'x'-1)<<endl;
                                        }
                                }
                }
        }
}[/mw_shl_code]
4:
答案:18岁
代码:
[mw_shl_code=cpp,true]#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
        int a[6];
        a[1] = 10;
        for (int i=2; i<=5; i++)
                a = a[i-1] + 2;
        cout<<a[5]<<endl;
}[/mw_shl_code]
5:
代码:
[mw_shl_code=cpp,true]void sort_for_link(NODE** pNode)
{
        NODE* pre;
        NODE* cur;

        if(NULL == pNode || NULL == *pNode)
                return;

        cur = (*pNode) ->next;
        (*pNode) ->next = NULL;

        while(cur)
        {
                pre = cur;
                cur = cur->next;
                insert_for_sort(pNode, pre);
        }

        return;
}
void insert_for_sort(NODE** pNode, NODE* Node)
{
        NODE* pre;
        NODE* cur;

        if(Node->data < (*pNode)->data)
        {
                Node->next = *pNode;
                *pNode = Node;
                return;
        }

        cur = *pNode;
        while(cur)
        {
                if(Node->data < cur->data)
                        break;
                pre = cur;
                cur = cur->next;
        }

        Node->next = pre->next;
        pre->next = Node;
        return;
}[/mw_shl_code]
6:
代码:
[mw_shl_code=cpp,true]char* strrev(const char* str)
{
        int len = strlen(str);
        char* tmp = new char[len + 1];
        strcpy(tmp,str);
        char* s = tmp;
        char* last = tmp + len - 1;
       
        while (last  > tmp)
        {
                *last ^= *tmp;
                *tmp ^= *last;
                *last ^= *tmp;
                last--;
                tmp++;
        }
  
        return s;
}[/mw_shl_code]
7:代码:
[mw_shl_code=cpp,true]#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
        int num;
        double ans;
        cout<<"请输入当月利润:";
        while (cin>>num)
        {
                ans = 0;
                if (num > 1000000)
                {
                        ans += (num-1000000)*0.01;
                        num = 1000000;
                }
                if (num > 600000)
                {
                        ans += (num-600000)*0.015;
                        num = 600000;
                }
                if (num > 400000)
                {
                        ans += (num-400000)*0.03;
                        num = 400000;
                }
                if (num > 200000)
                {
                        ans += (num-200000)*0.05;
                        num = 200000;
                }
                if (num > 100000)
                {
                        ans += (num-100000)*0.075;
                        num = 100000;
                }
                ans += num * 0.1;

                cout<<ans<<endl;
                cout<<"请输入当月利润:";
        }
}[/mw_shl_code]
8:
答案:1534
代码:
[mw_shl_code=cpp,true]#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
        int num = 1, i;
        for (i=1; i<10; i++)
        {
                num += 1;
                num *= 2;
        }
        cout<<num<<endl;
}[/mw_shl_code]
9:
[mw_shl_code=cpp,true]#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
        int a[100000], max, maxIndex, min, minIndex, i, n;
        cout<<"输入数组长度:";
        cin>>n;
        cout<<"数组:";
        for (i=0; i<n; i++)
                cin>>a;
        min = max = a[0];
        minIndex = maxIndex = 0;
        for (i=1; i<n; i++)
        {
                if (max < a)
                {
                        max = a;
                        maxIndex = i;
                }
                if (min > a)
                {
                        min = a;
                        minIndex = i;
                }
        }
        int tmp;
        tmp = a[0];
        a[0] = max;
        a[maxIndex] = tmp;
        if (minIndex == 0)
                minIndex = maxIndex;
        tmp = a[n-1];
        a[n-1] = min;
        a[minIndex] = tmp;
        cout<<"交换后的数组:";
        for (i=0; i<n; i++)
                cout<<a<<" ";
        cout<<endl;
}[/mw_shl_code]
10:
[mw_shl_code=cpp,true]//key为密钥,随机生成 key = rand()*256;
char * my_encrypt(char *input, int key)
{
        int len = strlen(input);
        char* tmp = new char[len + 1];
        
        for (int i=0; i<len; i++)
                tmp = (input * key) % 256;
        return tmp;
}[/mw_shl_code]

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 o(* ̄▽ ̄*)ブ 发糖

查看全部评分

绝世小攻
回复 支持 反对

使用道具 举报

该用户从未签到

7

主题

56

好友

1万

积分

第一章

积分
14325
发表于 2013-4-17 16:56:10 | 显示全部楼层
头次发这么长的帖子。。。加代码  民那慢慢看。。。。
1.题目:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程 找出1000以内的所有完数。
ans:1 6 28 496
code:
//竟然一个数自身不是它的因子。。。
#include <stdio.h>
#include <iostream>
int Sum(int x)
{
    int ans=0;
    for(int i=1;i*i<=x;i++)
    {
        if(x%i==0)ans+=i+x/i;
    }
    ans-=x;
    return ans;
}
int main()
{
    for(int i=1;i<=1000;i++)
        if(i==Sum(i))
            std::cout<<i<<" ";
    std::cout<<std::endl;
}
2.题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
s=299.609375 h=0.097656
code:
#include <stdio.h>
#include <math.h>
int main()
{
    double H=100;
    double s=H;
    int T=10;
    for(int i=1;i<T;i++)
    {
        s+=H;
        H/=2.0;
    }
    H/=2.0;
    printf("s=%.6f h=%.6f\n",s,H);
}
3.题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
a vs z
b vs x
c vs y
#include <stdio.h>
#include <algorithm>
#include <iostream>
char s1[]="abc";
char s2[]="xyz";
bool check()
{
    if(s2[0]=='x')return false;
    if(s2[2]=='x'||s2[2]=='z')return false;
    return true;
}
void print()
{
    for(int i=0;i<3;i++)
    {
        printf("%c vs %c\n",s1[i],s2[i]);
    }
}
int main()
{
    do
    {
        if(check())
        print();
    }
    while(std::next_permutation(s2,s2+3));//比较懒的写全排列 就用stl的偷懒了。。。
}
4.题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?
ans:18
code:
//= =。。。这种题。。。于是就按题目描述来了。。。
#include <stdio.h>
int f1(){return 10;};
int f2(){return f1()+2;};
int f3(){return f2()+2;};
int f4(){return f3()+2;};
int f5(){return f4()+2;};
int main()
{
    printf("%d\n",f5());
}
5.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法?
code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
struct node
{
    int num;
    node *next;
};
node *selectsort(node *head)//选择排序
{
    node *first;
    node *tail;
    node *Min;
    node *Min_pre;
    node *p;
    first=NULL;
    while(head!=NULL)
    {
        p=head;
        Min=head;
        while(p->next!=NULL)
        {
            if(p->next->num < Min->num)
                Min=p->next,Min_pre=p;
            p=p->next;
        }
        //新链表添加节点
        if(first==NULL)
        {
            first=Min;
            tail=Min;
        }
        else
        {
            tail->next=Min;
            tail=Min;
        }
        //旧链表删除节点
        if(Min==head)head=head->next;
        else
        {
            Min_pre->next=Min->next;
        }
    }
    tail->next=NULL;
    head=first;
    return head;
}
node *create()//创建链表
{
    node *head=(node *)malloc(sizeof(node));
    node *p=head;
    int x;
    while(std::cin>>x)
    {
        if(x==0)break;
        node *s=(node *)malloc(sizeof(node));
        s->num=x;
        p->next=s;
        p=s;
    }
    head=head->next;
    p->next=NULL;
    return head;
}
void print(node *head)//输出链表
{
    node *p=head;
    while(p!=NULL)
    {
        printf("%d ",p->num);
        p=p->next;
    }
    puts("");
}
int main()
{
    node *head;
    head=create();
    print(head);
    head=selectsort(head);
    puts("after sorted");
    print(head);
}
超级讨厌写链表 竟然要所有题目都做 只好勉强写一个了> <
用的选择排序 主要还是链表交换很恶心 快排 冒泡 堆排这种想都别想啦 换到死吧
6.编写反转字符串的程序,要求优化速度、优化空间。
code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
struct node
{
    int num;
    node *next;
};
node *reverse(node *head)//反转
{
    if(head==NULL||head->next==NULL)
    return head;
    node *p1=head;
    node *p2=p1->next;
    node *p3;
    while(p2!=NULL)
    {
        p3=p2->next;
        p2->next=p1;
        p1=p2;
        p2=p3;
    }
    head->next=NULL;
    head=p1;
    return head;
}
node *create()//创建链表
{
    node *head=(node *)malloc(sizeof(node));
    node *p=head;
    int x;
    while(std::cin>>x)
    {
        if(x==0)break;
        node *s=(node *)malloc(sizeof(node));
        s->num=x;
        p->next=s;
        p=s;
    }
    head=head->next;
    p->next=NULL;
    return head;
}
void print(node *head)//输出链表
{
    node *p=head;
    while(p!=NULL)
    {
        printf("%d ",p->num);
        p=p->next;
    }
    puts("");
}
int main()
{
    node *head;
    head=create();
    print(head);
    head=reverse(head);
    puts("after reverse");
    print(head);
}
这是链表的经典题了  类似于前插法建立链表 扫一遍OK 不要额外空间
时间复杂度O(n) 空间复杂度O(1)
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%提成,从键盘输入当月利润,求应发放奖金总数  
code:
#include <stdio.h>
double Max(double a,double b)
{
    return a>b?a:b;
}
double Min(double a,double b)
{
    return a<b?a:b;
}
double reward(double money)//分段函数 没啥可说的
{
    double ans=0;
    ans+=Min(money,10)*0.1;
    ans+=Max(0,Min(money,20)-10)*0.075;
    ans+=Max(0,Min(money,40)-20)*0.05;
    ans+=Max(0,Min(money,60)-40)*0.03;
    ans+=Max(0,Min(money,100)-60)*0.015;
    ans+=Max(0,money-100)*0.01;
    return ans;
}
int main()
{
    double m;
    puts("input the salary");
    while(scanf("%lf",&m)!=EOF)
    {
        printf("%.4f\n",reward(m));
        puts("input the salary");
    }
}
8.题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个     第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下     的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。  
ans:1534
#include <stdio.h>
int dfs(int day)
{
    if(day==10)
        return 1;
    else
    {
        return (dfs(day+1)+1)*2;
    }
}
void check()//单纯的写了个check检查下。。。
{
    int ans=dfs(1);
    for(int i=1;i<10;i++)
    {
        if(ans&1)puts("error");
        else ans=ans/2-1;
    }
    if(ans!=1)puts("error");
}
int main()
{
    check();
    printf("%d\n",dfs(1));
}
9.题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
code:
#include <stdio.h>
#include <math.h>
#include <iostream>
int main()
{
    int a[10000];
    int T;
    puts("input the size of array");
    std::cin>>T;
    puts("input the array(split by space)");
    int Max,Min,Maxi,Mini;
    for(int i=0;i<T;i++)
    {
        std::cin>>a[i];
        if(!i)
        {
            Max=a[i];
            Min=a[i];
            Maxi=i;
            Mini=i;
        }
        else
        {
            if(Max<a[i])Max=a[i],Maxi=i;
            if(Min>a[i])Min=a[i],Mini=i;
        }
    }
    std::swap(a[0],a[Maxi]);
    if(Mini==0)Mini=Maxi;
    std::swap(a[T-1],a[Mini]);
    for(int i=0;i<T;i++)
    {
        printf("%d%c",a[i],i==T-1?'\n':' ');
    }
}
//总感觉有bug的样子 Maxi Mini 0 T-1冲突了神马的。。。就这样吧 不想想了
10.选作题:设计并实现一个密码加密算法,要求加密后的密文不能依据程序而进行逆向解析(尽可能的不能被解析)
选作神马的不想搞了。。。其实我是没看懂什么是不能逆向解析。。。

点评

额 说解析其实也不够准确,说是破解或许就更清楚一些~  发表于 2013-4-17 20:12

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 o(* ̄▽ ̄*)ブ 发糖

查看全部评分

签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

29

主题

54

好友

1万

积分

懒人

尔等还不速速跪下~

积分
11600
发表于 2013-4-17 20:24:22 | 显示全部楼层
本帖最后由 繁尘、离梦 于 2013-4-17 20:28 编辑

@Mr_Alex
#include"iostream"
#include"cstring"
using namespace std;
int main()
{

        //好久没用 vs ,来一发测试先cout<<"hello world"<<endl;
        int max_num = 1000;

        int mark[100];//存放因子

        int pre=0;

        for(pre=0;pre<100;pre++)
                {
                        mark[pre]=0;
                }

        for(int i = 2 ; i <= max_num ; i++ )
        {


                int half=0;

                int kick_2=0;

                pre=0;

               

                if(i%2==0){

                        half=i/2;

                        kick_2=1;
                        
                }
                else {

                        half=(i+1)/2;

                        kick_2=0;

                }
                for(int mod_num=1;mod_num<=half;mod_num++)
                {
                        
                        if(i%mod_num==0)mark[pre++]=mod_num;

                        else continue;
               

                }

                int total=0;

                for(int p=0;p<pre;p++)
                {
                        total+=mark[p];

                        mark[p]=0;
                }

                if(total==i)cout<<i<<endl;



        }

        system("pause");







        return 0;
}

2-----------------------------------------------------


#include"iostream"
using namespace std;
int main()
{
        //温习了下等比数列,虽然电脑能循环算,但是编程的脑子不能这么死板啊,这题更适合用公式去算。
        //公式是一个积分的结果,精度相对更高些,如果弹起高度为1/3呢?除不尽呢

        int high=100;
        
        double S=0;

        

        S=(1.0-1.0/512)*400.0-100.0;//(第九次弹起落地,次数n为9,第一次少100落下)

        printf("取了六位小数,其实实际上是不到300的\n现在输出六位结果为%.6lf\n",S);
        
        printf("取了六位小数,弹起高度为%.6lf\n",100.0/1024.0);
        

        system("pause");


        return 0;
}





3--------------------------------




#include"iostream"
using namespace std;

bool deul(char m,char n)
{
        if(m=='a'&&n=='x')return false;
        if(m=='c'&&n=='x')return false;
        if(m=='c'&&n=='z')return false;
        return true;
}



int main()
{
        
        int map[3][3];
        


        for(char i='a';i<='c';i++)
        {

                for( char j='x';j<='z';j++)
                {
                        if(deul(i,j)==true)  map[i-'a'][j-'x']=1;
                        
                        else
                                map[i-'a'][j-'x']=0;


                }

        }

        for(int i=0;i<3;i++)
                for(int j=0;j<3;j++)
                        for(int k=0;k<3;k++)
                        {

                                if(i==j||i==k||j==k)continue;

                                if(map[0]==1&&map[1][j]==1&&map[2][k]==1)
                                {
                                        printf("a<----------->%c\n",'x'+i);

                                        printf("b<----------->%c\n",'x'+j);

                                        printf("c<----------->%c\n",'x'+k);
                                }

                        }

        system("pause");
        
        return 0;
}




4----------------------------------------------



#include"iostream"
using namespace std;
int main()
{
        int first=10;

        int temp=first;


        for(int i=1;i<=4;i++)
        {
                temp+=2;

        }
        cout<<"蛋疼的题目,我没看错吧:"<<temp<<endl;

        system("pause");

        return 0;
}



5-----------------------------


#include"iostream"
#include"stdlib.h"
using namespace std;

class list
{
public: list(float n)
                {
                        num=n;

                        nodemark=NULL;
                }
                list(list *node,float n)
                {
                        nodemark=node;

                        num=n;

                }
                list * nodemark;

                float num;

};
//上面是链表的类
int cmp(const void *a,const void *b)
{


        return *(int *)a - *(int *)b;//修改1和-1位置调整 从小到大或者从大到小排序
        // if(*c != *d)

        //  return *(d+1) - *(c+1);相等数据处理没必要,就随机好了两个数都是2,2和2的顺序无所谓
}

int main()
{


        cout<<"我先吐槽下这道题目:链表你妹啊,链表,链表能当饭吃,要排序也可先剥离数据,然后单纯对数据排序,把内存地址记录进数组,非常效率,只要读一次链表的数字,速度也可以到到nlogn,然后根据数字重新构建索引顺序,还是写个类做个单向链表吧,简单实现下"<<endl;

        int n=0;
        list *set_a[100];
        float num_store[100][2];
        while (cin>>n&&n>=2&&n<100)
        {
                cout<<"请输入"<<n<<"个数字(n必须>=2,并且小于1000,实际上几万个数应该没问题,我测试的时候数组开的尽可能小些,修改程序参数即可):"<<endl;

                float p;

                cin>>p;

                for(int l=0;l<100;l++)set_a[l]=NULL;

                list node=list(NULL,p);

                list *btm=&node;

                list *temp=NULL;

                list *forward=btm;

                for(int i=2;i<=n;i++)
                {
                        cin>>p;

                        temp=new list(forward,p);

                        forward=temp;

                }
                int s=0;
                while(temp!=NULL)
                {


                        num_store[0]=temp->num;

                        num_store[1]=s;

                        set_a=temp;

                        s++;

                        temp=temp->nodemark;



                }



                qsort(num_store[0],n,sizeof(num_store[0]),cmp);//快排,比较函数在main函数前面
                for(int prin=0;prin<n;prin++)
                {
                        cout<<num_store[prin][0]<<endl;
                }

                list *temp2;
                list *forward2=NULL;
                list *front=NULL;
                for(int prin=0;prin<n;prin++)//重组链表即可,链表地址已经在list【set】里面,重组方式的内存地址在num_store[1]里面
                {
                        if(prin==0)
                        {

                                temp2 = set_a[(int)(num_store[prin][1])];

                                front = temp2;

                                forward2 =temp2;

                        }


                        
                        temp2=set_a[(int)(num_store[prin][1])];

                        forward2->nodemark=temp2;
        
                        forward2=temp2;
                }

                temp2->nodemark=NULL;

                cout<<"链表遍历后:"<<endl;
                while(front!=NULL)
                {


                        cout<<front->num<<"---->";

                        front=front->nodemark;



                }
                cout<<"链表遍历结束"<<endl;

                //list node2=list(NULL,num_store[0][0]);

                // for(int prin=0;prin<n;prin++)//重组链表次序



                cout<<"以上为输出当前链表的数字从小到大排序后的内容。可以继续输入数字验证程序正确性,操作如上重复即可"<<endl;





                //list list1=list(1);

                //cout<<list1.num<<endl;








        }

        return 0;


}



6----------------------------------


#include"iostream"
using namespace std;
int main()
{
        cout<<"用string直接库函数有,看来楼主又要我用char数组?"<<endl;
        cout<<"空间指的是用一个数组?时间怎么看都是O(n),秒杀过,来把输入吧,别超过1000个字符"<<endl;
        char s[1000];
        while (gets(s))
        {
                //总不用我边输入边计算长度的吧?
               
               
                int len=strlen(s);

                if(len==0){cout<<"别闹,多输个字符会死"<<endl;continue;}

                char temp;

                int half;

                if(len%2==0)
                {
                        half=len/2;
                }
                else
                {
                        half=(len-1)/2;
                }

                for(int i=0;i<half;i++)
                        {
                                int oper=len-i-1;
                                temp= s;
                                s=s[oper];
                                s[oper]=temp;

                        }
                puts(s);


        }

        
}


7------------------------------------

#include"iostream"
using namespace std;
int main()
{
        cout<<"这题目可以用switch语句做很方便,但是作为懒人的我,我决定复制粘贴if更方便,还不用脑子"<<endl;
        cout<<"来吧输入数据吧"<<endl;
        

        double num;

        double profit=0;
        
        while (cin>>num&&num>=0)
        {

        
                profit=0;

               

               
                if(num<=100000)
                {
                        profit += num*0.1;
                }
                else profit +=10000;
                if(num>100000)
                {
                        if(num<=200000)  profit += (num-100000)*0.075 ;
                        else profit += 100000*0.075 ;
                }

                if(num>200000)
                {
                        if(num<=400000)  profit += (num-200000)*0.05 ;
                        else profit += 200000*0.05 ;
                        
                }
                if(num>400000)
                {
                        if(num<=600000)  profit += (num-600000)*0.03 ;
                        else profit += 200000*0.03 ;
                        
                }
                if(num>600000)
                {
                        if(num<=1000000)  profit += (num-600000)*0.015;
                        else profit += 400000*0.015 ;
                        
                }
                if(num>1000000)
                {
                  profit += (num-600000)*0.01 ;

                }
                cout<<profit<<endl;
                cout<<"来吧输入数据吧"<<endl;

        }
        

        return 0;
}



8-----------------------------------



#include"iostream"
using namespace std;
int main()
{
        int peach=1;
        int times=9;
        //while (cin>>times)
        //{把斜杠去掉可以输入次数来观察某一天天的桃子变化情况,
                peach=1;


                cout<<"Ps:能摘这么多桃子的猴子真心不容易"<<endl;
        for (int i=1;i<=times;i++)
        {
                peach=(peach+1)*2;

        
        }

        cout<<peach<<endl;

        
                //}
        system("pause");
        return 0;

}


9-----------------------------------



#include"iostream"
using namespace std;
int main()
{
        float a[1000];
        int n;
        cout<<"比大小总是数字的吧,ascll什么的总不会的吧,那我安心int了"<<endl;
        while (cin>>n&&n>0)
        {
                float max;
                int max_position=1;
                float min;
                int min_position=1;
                int end;
                for(int i=0;i<n;i++)
                {
                        float num;
                        
                        cin>>num;

                        if(i==0){max_position=i;min=num;min_position=i;end=i;a[0]=num; max=num;}

                        else
                        {
                                a=num;
                                if(max<num){max=num;max_position=i;}
                                //if(min>num){min=num;min_position=i;}

                                end=i;

                        }



                }
                        
                float temp=a[0];
                a[0]=max;
                a[max_position]=temp;
               
                //temp=a[end];
                //a[end]=min;
                //a[min_position]=temp;直接这么做是有漏洞的,为什么?思考去,前后万一有关联呢,第一次交换的数据呢?
        //保险的是再查对一次
                min=a[0];
                min_position=0;
                for(int i=0;i<=end;i++)
                {
                        if(a<min){min=a;min_position=i;}
                }
                temp=a[end];
                a[end]=min;
                a[min_position]=temp;


                for(int i=0;i<=end;i++)
                        cout<<a<<"---->"<<endl;
                cout<<"总算做完了"<<endl;

               
        }

}


10-------------------------------------

#include"iostream"
using namespace std;
int main()
{
        char s[32];
        int a[16];
        cout<<"加密,来个ascll加减,你知道一个数 永远不知道,它是哪两个数之和,比如 10,他可能是-1+11得来也可能9+1得来,你要猜测无数次,如果次数多了,无数次的N次方,就无法反解密了"<<endl;
        cout<<"这段,前一个数字已经被覆盖,相减和相加原理一样,只是我把前面的数字覆盖之后,你变无法猜测是哪几个数相减了"<<endl;
        while (gets(s))
        {
                int len=strlen(s);
                for(int i=len;i<32;i++)
                {
                        s='0';
                }
            
                for(int i=0;i<=15;i++)
                {
                        a=s+s[32-i-1];
                }
               
                a[15]=a[1]+a[15];
                for(int i=0;i<=14;i++)
                {
                        a-=a[i+1];
                }
               

                cout<<"加密后明文如下"<<endl;
                for(int i=0;i<=15;i++)
                cout<<a;
                cout<<endl;


        }
        

}


点评

好啦~~  发表于 2013-4-18 08:43
还有乱码吗?  发表于 2013-4-17 20:31
感谢参与,后面的部分代码有些乱的说,请排版一下呢~你可以在编辑框右上角找到插入代码的功能~~  发表于 2013-4-17 20:30

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3

查看全部评分

笔迹流下的那瞬间 ,   沉睡了   ,   我在迷惘......
[url=http://d.hiphotos.baidu.com/album/s%3D1400%3Bq
回复 支持 反对

使用道具 举报

签到天数: 538 天

连续签到: 37 天

[LV.9]以坛为家II

8

主题

10

好友

6万

积分

第三章

积分
61163
发表于 2013-4-17 22:57:55 | 显示全部楼层
本帖最后由 夏颉 于 2013-4-18 09:14 编辑

参与人ID(UID): 夏颉(244137)
参与类型: A 编程题目类
答案:由于代码有点长,不方便,所以已经打包上传,工程基于.NET FrameWork2.0,VS2005及其以上版本均可以打开;
            Release目录下为已编译程序,可双击直接运行!

=============================================


[mw_shl_code=csharp,true]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Collections;
using System.IO;

namespace AcOnline_gn00
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //一
            this.textBox1.Text = "1000";
            //二
            this.textBox3.Text = "100";
            this.textBox4.Text = "10";
            //第六题
            this.textBox9.Text = "abcdefghijklmnopqrstuvwxyz";
            //第七题
            this.textBox11.Text = "1654656";
            //第九题
            this.textBox14.Text = "123 25 45 765 345 99 34 55 77";
            this.textBox14.Enabled = false;
        }

        #region 第一题
        /// <summary>
        /// 第一题
        /// 一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程 找出1000以内的所有完数。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            int inputVal = Utils.StrToInt(this.textBox1.Text.Trim(),0);
            if(inputVal >= 6)
            {
                StringBuilder sb = new StringBuilder();
                List<int> array = new List<int>();
                int i,j,s;
                for (j = 2; j < inputVal;j++)
                {
                    s = j;
                    for (i = 1; i < j; i++)
                    {
                        if ((j % i) == 0)
                        {
                            s = s - i;
                            array.Add(i);
                        }
                    }
                    if (s == 0)
                    {
                        sb.Append(j + " ");
                    }
                }
                this.textBox2.Text = sb.ToString();
            }
            else
            {
                MessageBox.Show(this,"请输入大于5的值","提示",MessageBoxButtons.OK);
            }
        }
        #endregion

        #region 第二题
        /// <summary>
        /// 第二题
        /// 一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            float inputHigh = Utils.StrToFloat(this.textBox3.Text.Trim(), 0.00F);
            int inputF = Utils.StrToInt(this.textBox4.Text.Trim(),0);
            if (inputHigh > 0 && inputF > 0)
            {
                float allCount = -1 * inputHigh;
                float tmpHigh = inputHigh;
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < inputF; i++)
                {
                    allCount += tmpHigh * 2;
                    tmpHigh = tmpHigh / 2;
                }
                sb.Append(String.Format("共经过的{0}米;",allCount) + "\r\n");
                sb.Append(String.Format("第{0}次反弹的高度为{1}", inputF, tmpHigh));
                this.textBox5.Text = sb.ToString();
            }
            else
            {
                MessageBox.Show(this, "请输入大于0的值", "提示", MessageBoxButtons.OK);
            }
        }
        #endregion

        #region 第三题
        /// <summary>
        /// 第三题
        /// 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。
        /// 有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            //string[] arr_jia = { "a", "b", "c"};
            //string[] arr_yi = { "x", "y", "c"};
            StringBuilder sb = new StringBuilder();
            //i是a的对手,j是b的对手,k是c的对手
            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')
                                {
                                    sb.Append(String.Format("比赛顺序: a--{0}\tb--{1}\tc--{2}\r\n", i, j, k));
                                }
                            }
                        }
                    }
                }
            }
            this.textBox6.Text = sb.ToString();
        }
        #endregion

        #region 第四题
        /// <summary>
        /// 第四题
        /// 有5个人坐在一起,问第五个人多少岁?
        /// 他说比第4个人大2岁。
        /// 问第4个人岁数,他说比第3个人大2岁。
        /// 问第三个人,又说比第2人大两岁。
        /// 问第2个人,说比第一个人大两岁。
        /// 最后问第一个人,他说是10岁。请问第五个人多大?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            this.textBox7.Text = "第五个人的年龄:" + calage(5).ToString();
        }
        private int calage(int n)
        {
            int age;
            if(n == 1)
            {
                age = 10;
            }
            else
            {
                age = calage(n - 1) + 2;
            }
            return age;
        }
        #endregion

        #region 第五题
        /// <summary>
        /// 第五题
        /// 编写实现链表排序的一种算法。说明为什么你会选择用这样的方法?
        /// Start AWS:
        /// 由于我不会C/C++,这道题用C#作答 代码跟其它题相比稍多,所以就选择对单链表进行模拟排序
        /// 在本题的排序过程中,我发现冒泡排序和选择排序都要求内层循环从链表的末尾向前走,这明显是不合适的;所以我最终选择了插入排序算法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            Link head = GenerateLink();
            Link newHead = SortLink(head);
            Link curr = newHead;
            while (curr.Next != null)
            {
                sb.Append(curr.Next.Data + " ");
                curr = curr.Next;
            }
            this.textBox8.Text = sb.ToString();
        }

        public static Link GenerateLink()
        {
            Link element8 = new Link(null, 113);
            Link element7 = new Link(element8, 123);
            Link element6 = new Link(element7, 143);
            Link element5 = new Link(element6, 91);
            Link element4 = new Link(element5, 7);
            Link element3 = new Link(element4, 65);
            Link element2 = new Link(element3, 25);
            Link element1 = new Link(element2, 5);
            Link head = new Link(element1, int.MinValue);
            return head;
        }

        public static Link SortLink(Link head)
        {
            Link pre1 = head;
            Link pre2 = head.Next;
            Link min = null;
            for (Link curr1 = head.Next; curr1 != null; curr1 = min.Next)
            {
                if (curr1.Next == null)
                    break;
                min = curr1;
                for (Link curr2 = curr1.Next; curr2 != null; curr2 = curr2.Next)
                {
                    if (curr2.Data < curr1.Data)
                    {
                        min = curr2;
                        curr2 = curr1;
                        curr1 = min;

                        pre1.Next = curr1;
                        curr2.Next = curr1.Next;
                        curr1.Next = pre2;

                        if (pre2 != curr2)
                            pre2.Next = curr2;
                    }
                    pre2 = curr2;
                }
                pre1 = min;
                pre2 = min.Next;
            }
            return head;
        }

        #endregion

        #region 第六题
        /// <summary>
        /// 第六题
        /// 编写反转字符串的程序,要求优化速度、优化空间。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            int times = 1000000;
            string initStr = this.textBox9.Text;
            int strLen = initStr.Length;
            string[] resultStrArr = new string[strLen];
            string result = String.Empty;
            Stopwatch watch1 = new Stopwatch();
            watch1.Start();
            for (int i = 0; i < times; i++)
            {
                for (int j = strLen-1; j >= 0;j--)
                {
                    resultStrArr[strLen-j-1] = initStr.Substring(j,1);
                }
                result = String.Concat(resultStrArr);
            }
            watch1.Stop();
            this.textBox9.Text = result;
            this.textBox10.Text = watch1.Elapsed.ToString();
        }
        #endregion

        #region 第七题
        /// <summary>
        /// 第七题
        /// 企业发放的奖金根据利润提成。利润(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%提成,从键盘输入
        /// 当月利润,求应发放奖金总数  
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button7_Click(object sender, EventArgs e)
        {
            float inputVal = Utils.StrToFloat(this.textBox11.Text.Trim(), 0);
            if (inputVal >= 0)
            {
                float allCount = inputVal * 0.1F;
                if (inputVal > 100000)
                {
                    allCount += (inputVal - 100000) * 0.075F;
                    if (inputVal > 200000)
                    {
                        allCount += (inputVal - 200000) * 0.05F;
                        if (inputVal > 400000)
                        {
                            allCount += (inputVal - 200000) * 0.03F;
                            if (inputVal > 600000)
                            {
                                allCount += (inputVal - 200000) * 0.015F;
                                if (inputVal > 1000000)
                                {
                                    allCount += (inputVal - 200000) * 0.01F;
                                }
                            }
                        }
                    }
                }   
                this.textBox12.Text = allCount.ToString();
            }
            else
            {
                MessageBox.Show(this, "请输入大于0的值", "提示", MessageBoxButtons.OK);
            }
        }
        #endregion

        #region 第八题
        /// <summary>
        /// 第八题
        /// 猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个     
        /// 第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。
        /// 到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button8_Click(object sender, EventArgs e)
        {
            int result = 1;
            for (int i = 9; i > 0; i--)
            {
                result = (result + 1) * 2;
            }
            this.textBox13.Text = result.ToString();
        }
        #endregion

        #region 第九题
        /// <summary>
        /// 第九题
        /// 输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button9_Click(object sender, EventArgs e)
        {
            string[] initStrArr = this.textBox14.Text.Split(' ');
            int[] initIntArr = new int[initStrArr.Length];
            for(int i = 0;i<initIntArr.Length;i++)
            {
                initIntArr = Utils.StrToInt(initStrArr,0);
            }
            //int minIndex = 0;
            int min = 0;
            //int maxIndex = 0;
            int max = 0;
            //遍历数组,找出最大值,跟max交换,遍历数组,找出最小值,跟min交换
            for (int i = 0; i < initIntArr.Length;i++)
            {
                if (initIntArr < initIntArr[min])
                {
                    min = i;
                }
                if (initIntArr > initIntArr[max])
                {
                    //max = initIntArr;
                    max = i;
                }
            }
            int tmp = initIntArr[min];
            initIntArr[min] = initIntArr[0];
            initIntArr[0] = tmp;
            tmp = initIntArr[max];
            initIntArr[max] = initIntArr[initIntArr.Length - 1];
            initIntArr[initIntArr.Length - 1] = tmp;
            foreach (int item in initIntArr)
            {
                this.textBox15.Text += item.ToString() + " ";
            }
        }
        #endregion

        #region 第十题
        /// <summary>
        /// 第十题
        /// 设计并实现一个密码加密算法,要求加密后的密文不能依据程序而进行逆向解析(尽可能的不能被解析)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click_1(object sender, EventArgs e)
        {
            string s = "";
            s += Test("");
            s += Test("a");
            s += Test("abc");
            s += Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
            s += Test("abcdefghijklmnopqrstuvwxyz");
            s += Test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
            s += Test("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
            this.textBox16.Text = s;
        }

        private static UInt32 Message_Digest1 = 0x67452301;
        private static UInt32 Message_Digest2 = 0xEFCDAB89;
        private static UInt32 Message_Digest3 = 0x98BADCFE;
        private static UInt32 Message_Digest4 = 0x10325476;
        private static UInt32 Message_Digest5 = 0xC3D2E1F0;

        private static UInt32 SHA1CircularShift(int bits, UInt32 word)
        {
            return ((word << bits) & 0xFFFFFFFF) | (word) >> (32 - (bits));
        }

        private static void SHA1_Init()
        {
            Message_Digest1 = 0x67452301;
            Message_Digest2 = 0xEFCDAB89;
            Message_Digest3 = 0x98BADCFE;
            Message_Digest4 = 0x10325476;
            Message_Digest5 = 0xC3D2E1F0;
        }

        private static UInt32[] SHA1_Append(byte[] input)
        {
            int zeros = 0;
            int ones = 1;
            int size = 0;
            int n = input.Length;
            int m = n % 64;
            if (m < 56)
            {
                zeros = 55 - m;
                size = n - m + 64;
            }
            else if (m == 56)
            {
                zeros = 63;
                ones = 1;
                size = n + 8 + 64;
            }
            else
            {
                zeros = 63 - m + 56;
                size = n + 64 - m + 64;
            }

            ArrayList bs = new ArrayList(input);
            if (ones == 1)
            {
                bs.Add((byte)0x80); // 0x80 = 10000000
            }
            for (int i = 0; i < zeros; i++)
            {
                bs.Add((byte)0);
            }

            UInt64 N = (UInt64)n * 8;
            byte h8 = (byte)(N & 0xFF);
            byte h7 = (byte)((N >> 8) & 0xFF);
            byte h6 = (byte)((N >> 16) & 0xFF);
            byte h5 = (byte)((N >> 24) & 0xFF);
            byte h4 = (byte)((N >> 32) & 0xFF);
            byte h3 = (byte)((N >> 40) & 0xFF);
            byte h2 = (byte)((N >> 48) & 0xFF);
            byte h1 = (byte)(N >> 56);
            bs.Add(h1);
            bs.Add(h2);
            bs.Add(h3);
            bs.Add(h4);
            bs.Add(h5);
            bs.Add(h6);
            bs.Add(h7);
            bs.Add(h8);
            byte[] ts = (byte[])bs.ToArray(typeof(byte));

            /* Decodes input (byte[]) into output (UInt32[]). Assumes len is
             * a multiple of 4.
             */
            UInt32[] output = new UInt32[size / 4];
            for (Int64 i = 0, j = 0; i < size; j++, i += 4)
            {
                UInt32 temp = 0;
                temp = temp | (((UInt32)ts) << 24);
                temp = temp | (((UInt32)ts[i + 1]) << 16);
                temp = temp | (((UInt32)ts[i + 2]) << 8);
                temp = temp | (((UInt32)ts[i + 3]));
                output[j] = temp;
            }
            return output;
        }
        private static UInt32[] SHA1_Transform(UInt32[] x)
        {
            SHA1_Init();

            UInt32[] K = {0x5A827999,0x6ED9EBA1,0x8F1BBCDC,0xCA62C1D6};
            int t;
            UInt32 temp;
            UInt32[] W = new UInt32[80];
            UInt32 A, B, C, D, E;

            for (int k = 0; k < x.Length; k += 16)
            {
                for (t = 0; t < 16; t++)
                {
                    W[t] = x[t + k];
                }

                for (t = 16; t < 80; t++)
                {
                    W[t] = SHA1CircularShift(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]);
                }

                A = Message_Digest1;
                B = Message_Digest2;
                C = Message_Digest3;
                D = Message_Digest4;
                E = Message_Digest5;

                for (t = 0; t < 20; t++)
                {
                    temp = SHA1CircularShift(5, A) +
                        ((B & C) | ((~B) & D)) + E + W[t] + K[0];
                    temp &= 0xFFFFFFFF;
                    E = D;
                    D = C;
                    C = SHA1CircularShift(30, B);
                    B = A;
                    A = temp;
                }

                for (t = 20; t < 40; t++)
                {
                    temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[1];
                    temp &= 0xFFFFFFFF;
                    E = D;
                    D = C;
                    C = SHA1CircularShift(30, B);
                    B = A;
                    A = temp;
                }

                for (t = 40; t < 60; t++)
                {
                    temp = SHA1CircularShift(5, A) +
                        ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
                    temp &= 0xFFFFFFFF;
                    E = D;
                    D = C;
                    C = SHA1CircularShift(30, B);
                    B = A;
                    A = temp;
                }

                for (t = 60; t < 80; t++)
                {
                    temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[t] + K[3];
                    temp &= 0xFFFFFFFF;
                    E = D;
                    D = C;
                    C = SHA1CircularShift(30, B);
                    B = A;
                    A = temp;
                }

                Message_Digest1 = (Message_Digest1 + A) & 0xFFFFFFFF;
                Message_Digest2 = (Message_Digest2 + B) & 0xFFFFFFFF;
                Message_Digest3 = (Message_Digest3 + C) & 0xFFFFFFFF;
                Message_Digest4 = (Message_Digest4 + D) & 0xFFFFFFFF;
                Message_Digest5 = (Message_Digest5 + E) & 0xFFFFFFFF;
            }

            return new UInt32[] { Message_Digest1, Message_Digest2, Message_Digest3, Message_Digest4, Message_Digest5 };
        }
        public static string SHA1Array(UInt32[] input)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < input.Length; i++)
            {
                sb.Append(String.Format("{0:X8}", input).ToUpper());
            }

            return sb.ToString();
        }

        public static string MySHA1String(string message)
        {
            char[] c = message.ToCharArray();
            byte[] b = new byte[c.Length];
            for (int i = 0; i < c.Length; i++)
            {
                b = (byte)c;
            }
            UInt32[] output = SHA1_Append(b);
            UInt32[] str = SHA1_Transform(output);
            return SHA1Array(str);

        }
        public static string MySHA1File(string fileName)
        {
            FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read);
            byte[] array = new byte[fs.Length];
            fs.Read(array, 0, (int)fs.Length);
            fs.Close();
            UInt32[] output = SHA1_Append(array);
            UInt32[] str = SHA1_Transform(output);
            return SHA1Array(str);
        }
        

        public static string Test(string message)
        {
            return "\r\nSHA1 (\"" + message + "\") = " + MySHA1String(message);
        }

        #endregion

    }

    /// <summary>
    /// 五
    /// </summary>
    public class Link
    {
        public Link Next;
        public int Data;
        public Link(Link next, int data)
        {
            this.Next = next;
            this.Data = data;
        }
    }
}[/mw_shl_code]
[mw_shl_code=csharp,true]    public class Utils
    {
        public static int StrToInt(string str, int defValue)
        {
            int rtnValue = defValue;
            if (String.IsNullOrEmpty(str) || str.Trim().Length > 10)
            {
                return rtnValue;
            }
            bool IsInt = new Regex(@"^([-]|[0-9])[0-9]*(\.\w*)?$").IsMatch(str.Trim());//@"^([-]|[0-9])[0-9]*$"
            if (IsInt)
            {
                Int32.TryParse(str.Trim(), out rtnValue);
            }
            return rtnValue;
        }

        public static float StrToFloat(string strValue, float defValue)
        {
            float rtnValue = defValue;
            if ((strValue == null) || (strValue.Trim().Length > 10))
            {
                return rtnValue;
            }
            bool IsFloat = new Regex(@"^([-]|[0-9])[0-9]*(\.\w*)?$").IsMatch(strValue.Trim());
            if (IsFloat)
            {
                Single.TryParse(strValue, out rtnValue);
            }
            return rtnValue;
        }
    }[/mw_shl_code]








AcOnline_gn00.zip

114.4 KB, 阅读权限: 175, 下载次数: 1, 下载积分: 宅币 -50 枚, 活跃 1 ℃

点评

请把代码直接贴出来呢~  发表于 2013-4-18 08:43

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 o(* ̄▽ ̄*)ブ 发糖

查看全部评分

签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

3

主题

11

好友

6320

积分

序章

积分
6320
发表于 2013-4-17 23:58:16 | 显示全部楼层
参与人ID(UID): 弱弱的AR酱 (UID: 59677)
参与类型: A 编程题目类
答案:

语言:C++
CodeBlock10.05编译通过

#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
using namespace std;

/*第一题
int main()
{
    int i,j,k;
    for(i=2;i<1000;i++)
    {
        k=0;
        for(j=1;j<=i/2;j++)
            if (i%j==0) k+=j;
        if(k==i) cout<<k<<" ";
    }

}
*/

/*第二题
int main()
{
    double h=100;
    double s=0;
    for(int i=0;i<10;i++)
    {
        s+=h;
        h/=2;
        s+=h;
    }
    s-=h;

    cout<<"Total distance:"<<s<<endl;
    cout<<"10st bounce:"<<h<<endl;
}
*/

/*第三题
int main()
{
    //i for a, j for b, k for c
    //0 for x, 1 for y, 2 for z
    int i,j,k;
    char name[3]={'x','y','z'};
    for(i=0;i<3;i++) for(j=0;j<3;j++) for(k=0;k<3;k++)
    {
        if((i!=j&&i!=k&&j!=k)&&(i!=0&&k==1))
        {
        cout<<"a vs "<<name[i]<<endl;
        cout<<"b vs "<<name[j]<<endl;
        cout<<"c vs "<<name[k]<<endl;
        }
    }
}
*/

/*第四题
int main()
{
    int age[5];
    age[0]=10;
    age[1]=age[0]+2;
    age[2]=age[1]+2;
    age[3]=age[2]+2;
    age[4]=age[3]+2;
    cout<<"No.5 is "<<age[4]<<" years old...";
    //wtf?
}
*/

/*第五题
//ascending order 升序排列
//合并排序。是O(nlgn)的算法,速度比较快。
//相比于其他O(nlgn)算法比如快速排序,合并排序更适合于链表这种数据结构
//减少了链表上的位移操作
struct node
{
    int data;
    struct node *next;
};

node * merge(struct node *first, struct node *second)
{
    struct node *f1=first, *f2=second,*t,*l;
    if(f1->data>f2->data) {l=f2;f2=f2->next;} else {l=f1; f1=f1->next;}
    t=l;
    while(f1!=NULL&&f2!=NULL)
    {
        if(f2->data>f1->data) {t->next=f1;f1=f1->next;t=t->next;}
        else {t->next=f2;f2=f2->next;t=t->next;}
    }
    while(f1!=NULL) {t->next=f1;f1=f1->next;t=t->next;}
    while(f2!=NULL) {t->next=f2;f2=f2->next;t=t->next;}
    return l;
}

//排序的函数
node * mergeSort(node *l)
{
    if(l->next==NULL) return l;
    if(l->next->next==NULL)
    {
        if(l->data<=l->next->data) return l;
        l->next->next=l;
        node *t=l->next;
        l->next=NULL;
        return t;
    }
    node *t1=l,*t2=l;
    bool flag=false;
    while(t1!=NULL) {if(flag) t2=t2->next; t1=t1->next; flag=!flag;}
    t1=t2->next; t2->next=NULL;
    t1=mergeSort(t1);
    t2=mergeSort(l);
    l=merge(t1,t2);
}

void delnode(struct node *l)
{
    if(l->next!=NULL) delnode(l->next);
    if(l->next==NULL) delete(l);
}
//主程序生成一些随机数据测试排序
int main()
{
    struct node *l,*t;
    l=new node; t=l; l->data=12;
    for(int i=0;i<11;i++) {t->next=new node; t=t->next; t->data=rand()%20;} t->next=NULL;
    t=l;
    while(t!=NULL) {cout<<t->data<<" "; t=t->next;}
    cout<<endl;
    l=mergeSort(l);
    t=l;
    while(t!=NULL) {cout<<t->data<<" ";t=t->next;}
    delnode(l);
}
*/

/*第六题
//优化时间和空间是啥_(:з」∠)_
//大概就是这样?
void rev(char *s)
{
    char temp;
    int l=strlen(s);
    for(int i=0;i<l/2;i++)
    {
        temp=s[i]; s[i]=s[l-1-i]; s[l-1-i]=temp;
    }
}

int main()
{
    char s[]="American Shengdiyagoo";
    rev(s);
    cout<<s;
}
*/

/*第七题
float calc(float I)
{
    if(I<=100000) return I*0.1;
    if(I<=200000) return (I-100000)*0.075+calc(100000);
    if(I<=400000) return (I-200000)*0.05+calc(200000);
    if(I<=600000) return (I-400000)*0.03+calc(400000);
    if(I<=1000000) return (I-600000)*0.015+calc(600000);
    return (I-1000000)*0.01+calc(1000000);
}
int main()
{
    float I,bonus;
    cout<<"Input profit(I):";
    cin>>I;
    bonus=calc(I);
    cout<<"Bonus = "<<bonus;
}
*/

/*第八题
int main()
{
    int i,n=1;
    for(i=0;i<9;i++) n=2*(n+1);
    cout<<n;

}
*/

/*第九题
//设最大长度1000,输入全部为整数
//输入以ctrl+z结尾
//assume max length=1000
//assume inputs are integers
//input ends with ctrl+z
const int MAXLEN=1000;

int main()
{
    int i=0,max=-2139062143,min=2139062143,maxi=0,mini=0,data[MAXLEN],t;

    while(cin>>t) //input ends with ctrl+z
    {
        data[i]=t;
        if(t>max) {max=t;maxi=i;}
        if(t<min) {min=t;mini=i;}
        i++;
    }
    i--;
    t=data[0];data[0]=data[maxi];data[maxi]=t;
    t=data[i];data[i]=data[mini];data[mini]=t;
    for(t=0;t<=i;t++) cout<<data[t]<<" ";
}
*/

//第十题
//使用了十分简单的加密方法
//用和明文二进制长度相同的密匙,对其进行XOR操作得到密文
//密文XOR密匙,可以得到明文
//通过使用密匙key君,达到即使程序被反向分析的话密码也不会被破解的目的
//当然我感觉RSA更好,不过那个又不是我想出来的(ry
//总之是个十分简陋的程序= =
//只能加密int,但是加密一个字符串其实是一样的
int encode(int message, int key)
{
    return message^key;
}

int decode(int cipher, int key)
{
    return cipher^key;
}
//加密解密都一样就不吐槽了

//生成随机密匙的函数
//当然实际上用rand()很不靠谱的,不过既然是个小程序(ry
int keygen(int m)
{
    srand(time(NULL));
    int i=0;while((m/=2)>0) i++;
    int t=1;
    for(int j=0;j<i;j++) t=t*2+rand()%2;
    return t;
}

int main()
{
    int m=9933324;//这是明文,随便写啦……
    int key=keygen(m);
    int cipher=encode(m,key);
    cout<<"message="<<m<<endl;
    cout<<"key="<<key<<endl;
    cout<<"cipher="<<cipher<<endl;
    cout<<"deciphered="<<decode(cipher,key)<<endl;
}

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 o(* ̄▽ ̄*)ブ 发糖

查看全部评分

签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

签到天数: 538 天

连续签到: 37 天

[LV.9]以坛为家II

8

主题

10

好友

6万

积分

第三章

积分
61163
发表于 2013-4-18 09:09:33 | 显示全部楼层
本帖最后由 夏颉 于 2013-5-19 20:20 编辑

应用类答题: 先把此楼站住

AppName:流量统计
功能需求:由于我的手机移动GPRS上网套餐是有两个的,但是是按时间段区分的,具体情况是这样:0:00-9:00 B套餐;9:00-23:59 A套餐;目前我所能找到的流量统计应用貌似都不能按我自定义的时间段进行统计每个月中的流量消耗;所以决定自己写一个。
状态:已成功发布,关键需要提交源码吗?

点评

恩 期待你的作品~  发表于 2013-4-20 08:58
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

8

主题

71

好友

1万

积分

第一章

积分
12582
发表于 2013-4-19 20:29:03 | 显示全部楼层
本帖最后由 Azure0427 于 2013-4-30 22:08 编辑

参与人ID(UID): Azure0427(373434)
参与类型: A 编程题目类
答案:


【1】

[mw_shl_code=c,true]# include <stdio.h>
# include <math.h>

int main(void)
{
        int i, j, sum;
        for (i = 2; i < 1000; i++)
        {
                sum = 1;                                /* 用以存放因子和 */
                for(j = 2; j < sqrt(i); j++)
                {
                        if (i%j == 0)                /* 判断j是否是因子 */
                                sum = (j + i/j) + sum;                /* 得到i的因子和 */
                }

                if (sum == i)                        /* 判断i是否为完数 */
                        printf("%d is a perfect number.\n", i);
        }

        return 0;
}        

/* 若存在j为i的因子,则存在与j对称的因子(i/j),此时有j<sqrt(i) */

/*
在VC++6.0中的运行结果是:
----------------------------------------------
6 is a perfect number.
28 is a perfect number.
496 is a perfect number.
----------------------------------------------
*/
[/mw_shl_code]

【2】

[mw_shl_code=c,true]# include <stdio.h>

int main(void)
{
        int i;
        double sum;        
        double h(int);

        for(i = 1, sum = 100; i <= 10; i++)        /* 第一次下落时高度为100米,后反弹50米,下落50米…… */
        {
                sum = sum + 2 * h(i);
        }


        printf("The tenth landing altogether go through %lf meters.\n", sum);
        printf("The tenth landing rebound %lf meters.\n", h(10));

        return 0;
}

double h(int i)
{
        double t;
        if (i == 1)
                t = 100;                        /* 第一次高度为100米 */
        else t = h(i-1) / 2;        /* 第n次下落高度为第(n-1)次反弹高度,第n次反弹高度为第(n-1)次高度的一半 */

        return (t);
}

/*
在VC++6.0中的运行结果是:
-----------------------------------------------------------
The tenth landing altogether go through 499.609375 meters.
The tenth landing rebound 0.195313 meters.
-----------------------------------------------------------
*/[/mw_shl_code]

【3】

[mw_shl_code=c,true]# include <stdio.h>

int main(void)
{
        char a, b, c;
        char *p1, *p2, *p3;
        p1 = &a;        /* 使p1指向a,即指向a的对手 */
        p2 = &b;        /* 使p2指向b,即指向b的对手 */
        p3 = &c;        /* 使p3指向c,即指向c的对手 */

        for(a = 'x'; a <= 'z'; a++)                                                /* 假定a的对手 */
        {
                if (a != 'x')                                                                /* a不与x比 */
                {
                        for(b = 'x'; b <= 'z'; b++)                                /* 假定b的对手 */
                        {
                                if (b != a)                                                        /* b与a的对手不同 */
                                {
                                        for(c = 'x'; c <= 'z'; c++)                /* 假定c的对手*/
                                        {
                                                if (c == 'y') break;                /* c的对手不是x,y,即c的对手为y*/               
                                                else continue;
                                        }
                                }
                                else continue;
                                if ((c == 'y')&&(c != b)) break;                /* 若c的对手为y且c不与b的对手相同 */
                        }
                }
                else continue;
                if ((c == 'y')&&(c != a)) break;                                /* 若c的对手为y且c不与a的对手相同 */
        }

        printf("a against %c, b against %c, c against %c\n", *p1, *p2, *p3);

        return 0;
}

/* 由a不与x比,且c不与x,z比得:c与y比,a与z比;所以有b与x比 */

/*
在VC++6.0中的运行结果是:
---------------------------------------
a against z, b against x, c against y
---------------------------------------
*/[/mw_shl_code]

【4】

[mw_shl_code=c,true]# include <stdio.h>

int main(void)
{
        int age(int);
        
        printf("The fifth person is %d years old.\n", age(5));

        return 0;
}

int age(int i)
{
        int t;
        if (i == 1)                                
                 t = 10;                                /* 第一个人的岁数 */
        else t = age(i-1) + 2;                /* 第n个人比第(n-1)个大2岁 */
        return t;
}

/*
在VC++6.0中的运行结果是:
------------------------------------
The fifth person is 18 years old.
------------------------------------
*/[/mw_shl_code]

【5】
不会
【6】
不会
【7】

[mw_shl_code=c,true]# include <stdio.h>

int main(void)
{
        double i;

        printf("Plese input the profit:\n");
        scanf("lf", &i);

        if (i <= 100000)                                                        /* 利润在0~10W之间*/
                i += 0.1 * i;
        else if (i <= 200000)                                                /* 利润在10~20W之间*/
                i += 0.075 * i + 2500;
        else if (i <= 400000)                                                /* 利润在20~40W之间*/
                i += 0.05 * i + 7500;
        else if (i <= 600000)                                                /* 利润在40~60W之间*/
                i += 0.03 * i + 15500;
        else if (i <= 1000000)                                                /* 利润在60~100W之间*/
                i += 0.015 * i + 24500;
        else                                                                                /* 利润大于100W*/
                i += 0.001 * i + 29500;
               
        if (i >= 0)                                                                        /* 若利润I为合法输入,则输出*/
                printf("The final prise is : %lf\n", i);
        else                                                                                /* 此时,利润I为非法输入(小于0) */
                printf("The profit is error.\n");

        return 0;
}

/* 利润分段提成 */

/*
在VC++6.0中的运行结果是:
I
--------------------------------------
Plese input the profit:
100000
The final prise is : 110000.000000
--------------------------------------
II
--------------------------------------
Plese input the profit:
200000
The final prise is : 217500.000000
--------------------------------------
III
--------------------------------------
Plese input the profit:
4000000
The final prise is : 4033500.000000
--------------------------------------
IV
--------------------------------------
Plese input the profit:
567000
The final prise is : 599510.000000
--------------------------------------
V
--------------------------------------
Plese input the profit:
821900
The final prise is : 858728.500000
--------------------------------------
VI
--------------------------------------
Plese input the profit:
342000
The final prise is : 366600.000000
--------------------------------------
VII
--------------------------------------
Plese input the profit:
0
The final prise is : 0.000000
--------------------------------------
VIII
--------------------------------------
Plese input the profit:
-20
The profit is error.
--------------------------------------
*/[/mw_shl_code]

【8】

[mw_shl_code=c,true]# include <stdio.h>

int main(void)
{
        int amount(int);

        printf("The first day it picked %d peaches.\n", amount(1));

        return 0;
}

int amount(int i)
{
        int t;
        if (i == 10)
                t = 1;                                                        /* 第十天还剩一个 */
        else t = (amount(i+1) + 1) * 2;                /* 第n天的桃子数为第(n+1)加一的和的两倍 */

        return (t);
}

/* 第n天的桃子的数量,为第(n-1)天桃子数的一半再减一,所以有第n天的桃子数为第(n+1)加一的和的两倍 */

/*
在VC++6.0中的运行结果是:
---------------------------------------
The first day it picked 1534 peaches.
---------------------------------------*/
[/mw_shl_code]


【9】

[mw_shl_code=c,true]# include <stdio.h>

int main(void)
{
        double a[5];
        int i;

        printf("Plese input elements.(Up to 5)\n");
        for(i = 0; i < 5; i++)                                /* 输入数组*/
        {
                scanf("%lf", &a);
        }
        double max = a[0], min = a[0];

        for(i = 0; i < 5; i++)
        {
                if (max < a)
                        max = a;
                if (min > a)
                        min = a;
        }

        double t;                                                        /* 元素交换 */
        t = max; max = a[0]; a[0] = t;
        t = min; min = a[4]; a[4] = t;

        printf("The sort array is :\n");        /* 输出数组 */
        for(i = 0; i < 5; i++)
        {
                printf("%lf ", a);
                if (i == 4)
                        printf("\n");
        }

        return 0;
}

/*
在VC++6.0中的运行结果是:
-------------------------------------------------
Plese input elements.(Up to 5)
1 2 3 4 5
The sort array is :
5.000000 2.000000 3.000000 4.000000 1.000000
-------------------------------------------------
*/[/mw_shl_code]

【10】
不会

评分

参与人数 1宅币 +30 贡献 +5 元气(技能点) +3 收起 理由
Mr_Alex + 30 + 5 + 3 o(* ̄▽ ̄*)ブ 感谢参与先~

查看全部评分

签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

4

主题

14

好友

3071

积分

序章

积分
3071
发表于 2013-4-20 13:14:34 | 显示全部楼层
紫色的雨  (UID: 425486)
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

本版积分规则

小黑屋|手机版|技术宅(基宅) ( 粤ICP备18082987号-1 | 浙公网安备 33010902001746号 )

GMT+8, 2024-4-26 22:42 , Processed in 0.234101 second(s), 36 queries , Redis On.

Copyright © 2018 技术宅社区

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表