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

合作站点账号登陆

QQ登录

只需一步,快速开始

快捷导航
楼主: Mr_Alex
收起左侧

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

 关闭 [复制链接]

签到天数: 2 天

连续签到: 1 天

[LV.1]初来乍到

33

主题

86

好友

2万

积分

第一章

积分
26283
发表于 2013-4-22 11:14:22 | 显示全部楼层
本帖最后由 NorviNS松鼠 于 2013-7-1 00:21 编辑

参与人ID(UID):NorviNS松鼠
                     参与类型: A 编程题目类
                     答案:

第一题:
import java.awt.Dialog.ModalExclusionType;
import java.util.ArrayList;

public class Question1 {
//一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程 找出1000以内的所有完数。
//结果为:6,28,496
    ArrayList<Integer> yinZiList = new ArrayList<>();
    ArrayList<Integer> yesList = new ArrayList<>();

    public static void main(String[] args){
        Question1 question = new Question1();
        question.start();
    }



    public void start(){
        for(int i=1;i<1000;i++){
            if(check(i)){
            yesList.add(i);
            }
        }

    System.out.println(yesList);
    }


    public boolean check(int i){
        boolean oYes = false;
        int sum = 0;


        for(int j=1;j<i;j++){
            if(i%j == 0){
                sum = sum + j;
            }
        }


       if(sum == i){
           oYes = true;
       }
       return oYes;
      }
}


第二题:
public class Question2 {
//一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
//答案:第10次反弹0.09765625米
//         第10次落地时共经过51200.0米

    public static void main(String[] args){
        Question2 question = new Question2();
        question.start();
    }



    public void start(){
        double startHeight = 100;
        int time = 10;
        System.out.println("第"+time+"次反弹"+calculateHeight(startHeight,time)+"米");
        System.out.println("第"+time+"次落地时共经过"+calculateLength(startHeight,time)+"米");
    }

    public double calculateHeight(double h,int time){
        double lastHeight = h;

        for(int i=0;i<time;i++){
            lastHeight = lastHeight/2;
        }

        return lastHeight;
    }



    public double calculateLength(double h,int time){
        double length = h;

        for(int i=1;i<time;i++){
            length = length * 2;
        }

        return length;
    }
}


第四题:
public class Question4 {
//有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。
//问第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个人多大?
//答案:18


    public static void main(String[] args){
        Question4 question = new Question4();
        question.start();
    }



    public void start(){
        int fifth = 0;
        int time = 5;
        int first = 10;
        fifth = getAnswer(time,first);
        System.out.println(fifth);
    }



    private int getAnswer(int time,int first) {
        int age = first;

        for(int i=1;i<time;i++){
            age = age + 2;
        }

        return age;
    }
}


第九题:
import java.util.ArrayList;
import java.util.Scanner;

public class Question9 {
//输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。

    public static void main(String[] args){
        Question9 question = new Question9();
        question.start();
    }


       
    public void start(){
        System.out.println("请逐个输入数组中的数字,以ok结束输入。");
        Scanner scanner;
        String getInput;
        int inputNum;
        ArrayList<Integer> inputList = new ArrayList<>();
        boolean flag = true;

               
        while(flag){
            scanner = new Scanner(System.in);
            getInput = scanner.next();
            if(getInput.equals("ok")){
                flag = false;
            }
            else{
                inputNum = Integer.parseInt(getInput);
                inputList.add(inputNum);
            }
        }
        System.out.println("输入完毕,数组为:"+inputList);
               
        change(inputList);
               
    }


       
    public void change(ArrayList<Integer> inputList){
        int max = inputList.get(0);
        int min = inputList.get(0);
        int maxIndex = 0;
        int minIndex = 0;
               
        for(int i=0;i<inputList.size();i++){
            if(inputList.get(i)>max){
                max = inputList.get(i);
                maxIndex = i;
            }
            else if(inputList.get(i)<min){
            min = inputList.get(i);
            minIndex = i;
            }
        }
               
        inputList.set(maxIndex, inputList.get(0));
        inputList.set(0, max);
               
        inputList.set(minIndex, inputList.get(inputList.size()-1));
        inputList.set(inputList.size()-1, min);
               
        System.out.println(inputList);
               
    }
}


【完了我竟然忘了这回事!!!TAT。。。都没怎么调试应该大丈夫吧。。。。。。原谅我

点评

可以的~~  发表于 2013-4-22 11:46
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

签到天数: 1 天

连续签到: 1 天

[LV.1]初来乍到

2

主题

12

好友

4347

积分

序章

积分
4347
发表于 2013-4-22 18:35:01 | 显示全部楼层
- -啊,其实我好懒,不过尽然发现好多题目写过的。。。
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]);
        i++;
        max=min=area[1];
        while(scanf_s("%d",&area[i]))
        {
                i++;
                if(max < area[i])
                {max= area[i];max_number=i;}
                if(min > area[i])
                {min= area[i];min_number=1;}
        }

        int middle;
        middle=area[1];
        area[1]=area[max_number];
        area[max_number]=middle;
        middle=area[i];
        area[i]=area[min_number];
        area[min_number]=middle;

        for(min=1;min<=i;i++)
                printf("%d",area[min]);
return 0;
}

//9
题号在答案下面0 0

评分

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

查看全部评分

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

使用道具 举报

该用户从未签到

4

主题

6

好友

1768

积分

Continue

积分
1768
发表于 2013-4-23 15:32:04 | 显示全部楼层
本帖最后由 你说的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+" ");
        }
}

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

使用道具 举报

该用户从未签到

15

主题

13

好友

6328

积分

序章

积分
6328
发表于 2013-4-23 16:17:48 | 显示全部楼层
本帖最后由 夏尘安 于 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.选作题:设计并实现一个密码加密算法,要求加密后的密文不能依据程序而进行逆向解析(尽可能的不能被解析)

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

使用道具 举报

该用户从未签到

25

主题

18

好友

1万

积分

第一章

积分
13184
发表于 2013-4-23 20:32:58 | 显示全部楼层
本帖最后由 虹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);
}
第十题:
也暂时空着。。密码加密,我只看过理论知识。。。。

评分

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

查看全部评分

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

使用道具 举报

该用户从未签到

27

主题

178

好友

4万

积分

第二章

积分
44454
发表于 2013-4-24 09:47:45 | 显示全部楼层
本帖最后由 sora酱_ 于 2013-5-3 08:21 编辑

参与人ID(UID): sora酱_
参与类型: A 编程题目类
答案:
嗯嗯...其实是志在参与而已...
用滴是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肿么输出文件了啦!~
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 ("lease enter a key: ");
        String key = c.readLine ();
        c.println ("lease 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题都做了!~
这不科学啊啊啊啊啊!!!~
正确率目测一般就是了~( ̄▽ ̄")~
看咱从预订滴3题变成了10题都做滴份上求!给!糖!滴说~~~

点评

别人都是做9题的魂淡淡~~  发表于 2013-4-24 10:06
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

14

主题

22

好友

7919

积分

序章

积分
7919
发表于 2013-4-25 21:41:22 | 显示全部楼层
[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]
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

1

主题

9

好友

1525

积分

Continue

积分
1525
发表于 2013-4-25 22:16:42 | 显示全部楼层
本帖最后由 michaelan 于 2013-4-25 22:20 编辑

参与人ID(UID): michaelan(425509)
参与类型: A 编程题目类
答案:C++写的 虽然是新人但是态度认真的(^U^)ノ~YO
(1)

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     int ans[500];
  5.     int ans_count = 0;
  6.     for (int i = 1; i <= 1000; i++)
  7.     {
  8.         bool check = true;
  9.         int sum = 0;
  10.         for (int j = 1; j < i; j++)
  11.             if (i % j == 0)
  12.                 sum += j;
  13.         if (sum == i)
  14.         {
  15.             ans[ans_count++] = i;
  16.             printf("%d\n", i);
  17.         }
  18.     }
  19.     return 0;
复制代码
(2)

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     double height = 100.0;
  5.     double journey = 100.0;
  6.     for (int i = 1; i < 10; i++)
  7.     {
  8.         journey += height;
  9.         height /= 2.0;
  10.     }
  11.     height /= 2.0;
  12.     printf("journey = %lf\nheight = %lf\n", journey, height);
  13.     return 0;
  14. }
复制代码
(3)

  1. #include <stdio.h>

  2. int print(int a, char b)
  3. {
  4.     char c;
  5.     if (a == 1)
  6.         c = 'x';
  7.     else if (a == 2)
  8.         c = 'y';
  9.     else
  10.         c = 'z';
  11.     printf("%c-%c\n", b, c);
  12. }

  13. int main()
  14. {
  15.     int a, b, c;    //  1:x 2:y 3:z
  16.     for (a = 1; a <= 3; a++)
  17.         for (b = 1; b <=3; b++)
  18.             if (a != b)
  19.             {
  20.                 c = 6 - a - b;
  21.                 if (a == 1 || c == 1 || c == 3)
  22.                     continue;
  23.                 print(a, 'a');
  24.                 print(b, 'b');
  25.                 print(c, 'c');
  26.             }
  27.     return 0;
  28. }
复制代码
(4)

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     int age[6];
  5.     age[1] = 10;
  6.     age[2] = age[1] + 2;
  7.     age[3] = age[2] + 2;
  8.     age[4] = age[3] + 2;
  9.     age[5] = age[4] + 2;
  10.     printf("age=%d\n", age[5]);
  11.     return 0;
  12. }
复制代码
(5)

  1. #include <stdio.h>

  2. /*  就当是正整数排序吧 ,输入若干个数,以-1结尾
  3. *  输出的话从小到大排序好了
  4. *  选择的是插入排序咯,因为链表插入快嘛,要利用起来哟
  5. */

  6. struct My_Link
  7. {
  8.     int val;
  9.     My_Link* next;
  10. };

  11. int main()
  12. {
  13.     My_Link* head = new My_Link;
  14.     head->val = -1;
  15.     head->next = NULL;

  16.     // input data and sort
  17.     int a;
  18.     scanf("%d", &a);
  19.     while (a >= 0)
  20.     {
  21.         My_Link* new_node = new My_Link;
  22.         new_node->val = a;
  23.         new_node->next = NULL;

  24.         My_Link* now = head->next;
  25.         My_Link* last = head;
  26.         while (now != NULL && now->val < a)
  27.         {
  28.             last = now;
  29.             now = now->next;
  30.         }
  31.         new_node->next = last->next;
  32.         last->next = new_node;

  33.         scanf("%d", &a);
  34.     }

  35.     // print data
  36.     My_Link* now_node = head->next;
  37.     while (now_node != NULL)
  38.     {
  39.         printf("%d\n", now_node->val);
  40.         now_node = now_node -> next;
  41.     }

  42.     // recover memory
  43.     while (head != NULL)
  44.     {
  45.         now_node = head;
  46.         head = head->next;
  47.         delete now_node;
  48.     }
  49.     return 0;
  50. }
复制代码
(6)

  1. #include <stdio.h>
  2. #include <string.h>

  3. void s_reverse_n(char* s, int n)
  4. {
  5.     for (int i = 0; i < n / 2; i++)
  6.     {
  7.         char p = s[i];
  8.         s[i] = s[n - i - 1];
  9.         s[n - i - 1] = p;
  10.     }
  11. }

  12. int main()
  13. {
  14.     char a[50];
  15.     strcpy(a, "Hello world.");
  16.     s_reverse_n(a, strlen(a));
  17.     printf("%s\n", a);
  18.     return 0;
  19. }
复制代码
(7)

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     double profit;
  5.     printf("profit = $ ");
  6.     scanf("%lf", &profit);

  7.     double bonus = 0.0;
  8.     if (profit <= 100000)
  9.         bonus = profit * 0.1;
  10.     else if (profit <= 200000)
  11.         bonus = 10000 + (profit - 100000) * 0.075;
  12.     else if (profit <= 400000)
  13.         bonus = 17500 + (profit - 200000) * 0.05;
  14.     else if (profit <= 600000)
  15.         bonus = 27500 + (profit - 400000) * 0.03;
  16.     else if (profit <= 1000000)
  17.         bonus = 33500 + (profit - 600000) * 0.015;
  18.     else
  19.         bonus = 39500 + (profit - 1000000) * 0.01;

  20.     printf("bonus = $ %lf", bonus);
  21.     return 0;
  22. }
复制代码
(8)

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     int ans = 1;
  5.     // 9 times
  6.     for (int i = 0; i < 9; i++)
  7.     {
  8.        ans += 1;
  9.        ans *= 2;
  10.     }
  11.     printf("%d\n", ans);
  12.     return 0;
  13. }
复制代码
(9)

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     int a[50];
  5.     int n;
  6.     int max_i, min_i;

  7.     printf("Input N = ");
  8.     scanf("%d", &n);
  9.     printf("Input %d numbers : ", n);
  10.     for (int i = 0; i < n; i++)
  11.         scanf("%d", &a[i]);
  12.     max_i = 0;
  13.     for (int i = 1; i < n; i++)
  14.         if (a[i] > a[max_i])
  15.             max_i = i;
  16.     int tmp = a[0];
  17.     a[0] = a[max_i];
  18.     a[max_i] = tmp;

  19.     min_i = 0;
  20.     for (int i = 1; i < n; i++)
  21.         if (a[i] < a[min_i])
  22.             min_i = i;
  23.     tmp = a[0];
  24.     tmp = a[n - 1];
  25.     a[n - 1] = a[min_i];
  26.     a[min_i] = tmp;

  27.     for (int i = 0; i < n; i++)
  28.         printf("%d ", a[i]);
  29.     printf("\n");
  30.     return 0;
  31. }
复制代码
(10)

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>

  5. /*  以下实现的是RSA算法的阉割版
  6. *  当然看着代码是可以破解的,因为把解密用的密匙也写在这了,实际中,P和Q是可以抛弃的,使用N、e进行加密,使用N、d进行解密
  7. */

  8. const unsigned long long P = 12301;
  9. const unsigned long long Q = 3217;

  10. unsigned long long gcd(unsigned long long a, unsigned long long b)
  11. {
  12.     if (b == 0)
  13.         return a;
  14.     else
  15.         return gcd(b, a % b);
  16. }

  17. unsigned long long x, y;
  18. void extend_Eulid(unsigned long long a, unsigned long long b)
  19. {
  20.     if(b == 0)
  21.     {
  22.         x = 1;
  23.         y = 0;
  24.     }
  25.     else
  26.     {
  27.         extend_Eulid(b, a%b);
  28.         unsigned long long temp = x;
  29.         x = y;
  30.         y = temp - a / b * y;
  31.     }
  32. }

  33. void get_key(unsigned long long P, unsigned long long Q, unsigned long long &N, unsigned long long &e, unsigned long long &d)
  34. {
  35.     N = P * Q;
  36.     unsigned long long R1 = P - 1;
  37.     unsigned long long R2 = Q - 1;
  38.     unsigned long long R = R1 * R2;
  39.     unsigned long long one = 1;
  40.     e = (P + Q) * ((long long) rand()) / 65535;
  41.     while (gcd(e, R) != 1)
  42.         e = e + one;
  43.     extend_Eulid(e, R);
  44.     d = x % R;
  45. }

  46. // return a^b (mod c)
  47. unsigned long long power(unsigned long long a, unsigned long long b, unsigned long long c)
  48. {
  49.     unsigned long long two = 2;
  50.     unsigned long long res = 1;
  51.     while (b > 0)
  52.     {
  53.         if (b % two == 1)
  54.             res = (res * a) % c;
  55.         a = (a * a) % c;
  56.         b = b / two;
  57.     }
  58.     return res;
  59. }

  60. void encode(unsigned long long code[], int& code_len, char s[], int len, unsigned long long N, unsigned long long e)
  61. {
  62.     unsigned long long M = 0;
  63.     unsigned long long ONE_CHAR = 128;

  64.     code_len = 0;
  65.     int c = 0;
  66.     for (int i = 0; i < len; i++)
  67.     {
  68.         M = M * ONE_CHAR + ((unsigned long long) s[i]);
  69.         c++;
  70.         if (c % 3 == 0)
  71.         {
  72.             code[code_len++] = M;
  73.             M = 0;
  74.             c = 0;
  75.         }
  76.     }
  77.     if (c != 0)
  78.         code[code_len++] = M;
  79.     for (int i = 0; i < code_len; i++)
  80.     {
  81.         code[i] = power(code[i], e, N);
  82.     }
  83. }

  84. void decode(unsigned long long code[], int code_len, char s[], int &len, unsigned long long N, unsigned long long d)
  85. {
  86.     unsigned long long ONE_CHAR = 128;
  87.     len = 0;
  88.     int last_len = 0;
  89.     for (int i = 0; i < code_len; i++)
  90.     {
  91.         unsigned long long M = power(code[i], d, N);
  92.         while (M > 0)
  93.         {
  94.             s[len++] = (unsigned char) (M % ONE_CHAR);
  95.             M = M / ONE_CHAR;
  96.         }
  97.         char q = s[last_len];
  98.         s[last_len] = s[len - 1];
  99.         s[len - 1] = q;
  100.         last_len = len;
  101.     }
  102. }

  103. int main()
  104. {
  105.     srand(time(0));

  106.     unsigned long long N, e, d;
  107.     get_key(P, Q, N, e, d);
  108.     printf("N=%I64d\ne=%I64d\nd=%I64d\n", N, e, d);

  109.     printf("-----------------------------\n");
  110.     printf("Please input a string (length <= 20):\n");
  111.     char s[20];
  112.     gets(s);

  113.     unsigned long long c[20];
  114.     int c_len = 0;
  115.     encode(c, c_len, s, strlen(s), N, e);
  116.     printf("After coding m = ");
  117.     for (int i = 0; i < c_len; i++)
  118.         printf("%I64d ", c[i]);
  119.     printf("\n");

  120.     printf("After decoding s = ");
  121.     int len;
  122.     char t[20];
  123.     decode(c, c_len, t, len, N, d);
  124.     for (int i = 0; i < len; i++)
  125.         printf("%c", t[i]);
  126.     printf("\n");

  127.     return 0;
  128. }
复制代码

评分

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

查看全部评分

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

使用道具 举报

该用户从未签到

16

主题

39

好友

4万

积分

第二章

积分
40937
发表于 2013-4-26 13:13:55 | 显示全部楼层
太简单了- -作为在学校上计算机竞赛的人来说

点评

二次提醒,如果不是因为参与而回复此帖,将会被看做是水,会被扣糖的哟~~  发表于 2013-4-27 08:39
所以你是要参加了是吗 ?  发表于 2013-4-26 14:33

评分

参与人数 1宅币 -20 贡献 -5 收起 理由
Mr_Alex -20 -5 水贴

查看全部评分

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

使用道具 举报

该用户从未签到

2

主题

11

好友

3212

积分

序章

积分
3212
发表于 2013-4-27 19:22:57 | 显示全部楼层
本帖最后由 蔚离 于 2013-4-27 19:28 编辑

参与人ID(UID): 蔚离(206624)
参与类型: A 编程题目类
1、
void one(){
        for(int i=1;i<1000;i++){
            int sum=0;
            for(int j=1;j<i;j++){
                if(i%j==0)
                    sum=sum+j;
            }
            if(sum==i)
                System.out.println(i);
        }
    }
}
2、
void two(){
        float height=100,s=height;
        for(int i=1;i<9;i++){
                s=s+height;
                height=height/2;
        }
        System.out.println("第10次:共走了"+s+"米,反弹"+height+"米");
}
3、
void three(){
        String[] arr=new String[3];
        //初始化
        for(int i=0;i<3;i++)
                arr="xyz";
        //a不和x比
        arr[0]=arr[0].replace('x',' ').trim();
        //c不和x,z比
        arr[2]=arr[2].replace('x',' ').trim();
        arr[2]=arr[2].replace('z',' ').trim();
        while(arr[0].length()!=1 || arr[1].length()!=1 || arr[2].length()!=1){
                for(int i=0;i<3;i++){
            if(arr.length()==1){
                                    char temp=arr.charAt(0);
                    for(int j=0;j<3;j++){
                            if(j!=i)
                                arr[j]=arr[j].replace(temp,' ').trim();
                                    }
                            }
                       }
        }
        for(int i=0;i<3;i++)
        System.out.println((char)(i+97)+" vs "+arr);
}
4、
void four(){
        int[] ages=new int[5];
        ages[0]=10;
        for(int i=1;i<5;i++)
                ages=ages[i-1]+2;
        System.out.println("第五个人"+ages[4]+"岁");
}
5、
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
void five(){
        Scanner input=new Scanner(System.in);
        System.out.print("请输入一组数字,用空格分开:");
        String s=input.nextLine();
        String[] sarr=s.split(" ");
        List list=new ArrayList();
        int min,pos;
        for(int i=0;i<sarr.length;i++){
                min=Integer.parseInt(sarr);
                pos=i;
                for(int j=i;j<sarr.length;j++){
                        if(Integer.parseInt(sarr[j])<min){
                                min=Integer.parseInt(sarr[j]);
                                pos=j;
                        }
                }
                sarr[pos]=sarr;
                sarr=String.valueOf(min);
                list.add(min);
        }
        for(int i=0;i<list.size();i++)
                System.out.println(list.get(i));
}
6、
import java.util.Scanner;
void six(){
        Scanner input=new Scanner(System.in);
        System.out.print("请输入:");
        String s=input.nextLine();
        char[] arr=s.toCharArray();
        System.out.print("翻转后:");
        for(int i=0;i<s.length()/2;i++){
                char temp=arr[s.length()-1-i];
                arr[s.length()-1-i]=arr;
                arr=temp;
        }
        System.out.print(arr);
}
7、
import java.util.Scanner;
void seven(){
        Scanner input=new Scanner(System.in);
        System.out.print("请输入利润(单位为万元):");
        double money=Double.parseDouble(input.nextLine()),get=0;
        if(money<=10)
                get=money*0.1;
        else if(money<20)
                get=(money-10)*0.075+10*0.1;
        else if(money<40)
                get=(money-20)*0.05+10*0.075+10*0.1;
        else if(money<60)
                get=(money-40)*0.03+20*0.05+10*0.075+10*0.1;
        else if(money<100)
                get=(money-60)*0.015+20*0.03+20*0.05+10*0.075+10*0.1;
        else if(money>=100)
                get=(money-100)*0.01+40*0.015+20*0.03+20*0.05+10*0.075+10*0.1;
        System.out.print("奖金总数"+get+"万元");
}
8、
void eight(){
        int peach=1;
        for(int i=10;i>1;i--){
                System.out.println("第"+i+"天有"+peach+"个桃子");
                peach=(peach+1)*2;
        }
        System.out.println("第1天有"+peach+"个桃子");
}
9、
import java.util.Scanner;
void nine(){
        Scanner input=new Scanner(System.in);
        System.out.print("请输入一组数字,用空格分开:");
        String s=input.nextLine();
        String[] sarr=s.split(" ");
        int[] arr=new int[sarr.length];
        for(int i=0;i<sarr.length;i++)
                arr=Integer.parseInt(sarr);
        int min=arr[0],posmin=0,max=min,posmax=0;
        for(int i=0;i<sarr.length;i++){
                if(Integer.parseInt(sarr)<min){
                        min=Integer.parseInt(sarr);
                        posmin=i;
                }
                if(Integer.parseInt(sarr)>max){
                        max=Integer.parseInt(sarr);
                        posmax=i;
                }
        }
        arr[posmax]=arr[0];
        arr[0]=max;
        arr[posmin]=arr[sarr.length-1];
        arr[sarr.length-1]=min;
        for(int i=0;i<sarr.length;i++)
                System.out.println(arr);
}

评分

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

查看全部评分

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

使用道具 举报

该用户从未签到

15

主题

29

好友

1万

积分

第一章

积分
12726
发表于 2013-4-28 10:40:34 | 显示全部楼层
参与人ID(UID):失控的变压器(363280)
参与类型: A 编程题目类
答案:........
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

28

主题

103

好友

9783

积分

技术宅认证程序员

苦逼,受剥削人民

积分
9783
发表于 2013-4-28 22:56:17 | 显示全部楼层
本帖最后由 秋声赋 于 2013-6-7 12:00 编辑

好吧
我想当然的认为能写WP的APP  结果发现没有
似乎已经没时间写安卓的了
等15号 看看能不能写完吧

点评

求编辑~  发表于 2013-6-6 10:49
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

72

主题

84

好友

2万

积分

第一章

积分
22718
发表于 2013-5-2 23:40:16 | 显示全部楼层
本帖最后由 天堂at人间 于 2013-5-3 23:00 编辑

参与人ID(UID): 天堂at人间  (370621)
参与类型: A 编程题目类
答案:

1

#include<iostream>
using namespace std;

int main()
{
        int a,i,j;
        for(a=2;a<=1000;a++){
                j=0;
                for(i=1;i<a;i++){
                        
                        if(a%i==0){j=j+i;}
                        
        
        
                }
                if(a==j){cout<<a<<endl;}
        }

        return 0;
}


2

#include<iostream>

using namespace std;

int main()
{
        
        float sum=0,current,i,j;
        current=50;
        for(i=1;i<=(10-1);i++){
               
                sum=sum+current*2;
                current=current/2;
        
        }
        sum=sum+100;
        cout<<"第10次落地时,共经过"<<sum<<endl;
        cout<<"第10次反弹多高?"<<current;
        return 0;
}


3

#include <cstdio>
#include <cstdlib>
int main(int argc, char **argv)
{
    int i,j;
    for(i='A';i<='C';i++)
        for(j='X';j<='Z';j++)
            if(!((i=='A'&&j=='X')||(i=='C'&&(j=='X'||j=='Z'))))
                printf("%c----%c\n",i,j);
    system("pause");
    return 0;
}


4
#include <cstdio>
#include <cstdlib>

int age(int n)
{
    int c;
    if( n==1 ) c=10;
    else   c=age(n-1)+2;
    return c;
}

int main(int argc, char **argv)
{
    printf("%d \n",age(5)) ;
    system("pause");
    return 0;
}


5

#include <iostream>
#include <cstdlib>
#include <list>
using namespace std;

void my_sort(list<int> &l)
{
    for(list<int>::iterator i = l.begin();
        i != l.end();
        ++i)
        for(list<int>::iterator j = i;
            j != l.end();
            ++j)
        {
            if(i == j) continue;
            if(*i > *j){
                int t = *i;
                *i = *j;
                *j = t;
            }
        }
}

int main(int argc, char *argv[])
{
    list<int> l;
    int t;
    cout << "输入数字,以-1结束:";
    while(cin>>t, t!=-1){
        l.push_back(t);
    }
    my_sort(l);
    for(list<int>::iterator iter = l.begin();
        iter != l.end();
        ++iter)
    {
        cout << *iter << " ";
    }
    system("pause");
    return 0;
}
6

#include <stdio.h>
#include <cstdlib>
void reverse(char *_str,int len)
{
    char*p=_str,*q=_str+len-1;
    len/=2;
    while(len>0)
    {
        *p=*p^*q;
        *q=*p^*q;
        *p=*p^*q;

        p++;
        q--;
        len--;
    }
}

int main()
{
    char str0[11]= "0123456789";
    reverse(str0,sizeof(str0)-1);
    printf("str0 = %s\n",str0);

    char str1[6]="01234";
    reverse(str1,sizeof(str1)-1);
    printf("str1 = %s",str1);
    system("pause");
    return 0;
}


7
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
    long i;
    float bonus,bon1,bon2,bon4,bon6,bon10;
    int c;
    bon1=100000*0.1;
    bon2=bon1+100000*0.075;
    bon4=bon2+200000*0.05;
    bon6=bon4+200000*0.03;
    bon10=bon6+400000*0.015;
    cout<<"请输入当月利润:";
    cin>>i;
    c=i/100000;
    if (c>10) c=10;
    switch(c)
    {
    case 0: bonus=i*0.1; break;
    case 1: bonus=bon1+(i-100000)*0.075; break;
    case 2:
    case 3: bonus=bon2+(i-200000)*0.05;break;
    case 4:
    case 5: bonus=bon4+(i-400000)*0.03;break;
    case 6:
    case 7:
    case 8:
    case 9: bonus=bon6+(i-600000)*0.015; break;
    case 10: bonus=bon10+(i-1000000)*0.01;
    }
    cout<<"奖金为:"<<bonus<<endl;
    system("pause");
    return 0;
}



8
#include <cstdio>
#include <cstdlib>
int main(int argc, char **argv)
{
    int day,x1,x2;
    day=9;
    x2=1;
    while(day>0)
    {
        x1=(x2+1)*2;
        x2=x1;
        day--;
    }
    printf("总桃子数为: %d\n",x1);
    system("pause");
    return 0;
}


9


#include<iostream>

using namespace std;

int main()
{
        
        int t,compare,record,a[10];
        cout<<"请输入10个数:";
        for(int k=0;k<=9;k++)
        cin>>a[k];
        compare=a[0];

        for(k=0;k<=9;k++){
                if(a[k]>compare){compare=a[k];record=k;}

        }
        t=a[0];
        a[0]=a[record];
        a[record]=t;

        for(k=0;k<=9;k++){
                if(a[k]<compare){compare=a[k];record=k;}

        }
        t=a[9];
        a[9]=a[record];
        a[record]=t;

        for(k=0;k<=9;k++)
        cout<<a[k]<<" ";
        return 0;
}




评分

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

查看全部评分

明天不比今天更美,珍惜当下人生
回复 支持 反对

使用道具 举报

签到天数: 1 天

连续签到: 1 天

[LV.1]初来乍到

158

主题

79

好友

2万

积分

第一章

积分
22632
发表于 2013-5-4 10:27:57 | 显示全部楼层
本帖最后由 jiangguo2 于 2013-5-5 15:42 编辑

参赛ID:jiangguoer
参与类型:A
答案:
/*8.到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。  */
#include<stdio.h>
int main(void){
int day=10,peach=1;
for(;day>1;day--){
peach+=1;
peach*=2;
}
printf("the monkey got %d peaches in total.\n",peach);
return 0;
}

//
#include<stdio.h>
int main(void){
float in,out=0;
printf("How much did you get?\n");
scanf("%f",&in);
if(in<=100000)out=0.1*in;
else if(in<=200000){in-=100000;out=10000+0.075*in;}
else if(in<=400000){in-=200000;out=17500+0.05*in;}
else if(in<=600000){in-=400000;out=27500+0.03*in;}
else if(in<=1000000){in-=600000;out=33500+0.015*in;}

else{in-=1000000;out=39500+0.01*in;}

printf("You got %f.\n",out);
return 0;
}


//
#include<stdio.h>
int main(void){
int a,b,c,d,e;
a=10;
b=a+2;
c=b+2;
d=c+2;
e=d+2;
printf("%d",e);
return 0;
}

/*output:
18*/
/*3.题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。
有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。*/
#include<stdio.h>
int main(void)
{
int a=1,b=2,c=3;
int x,y,z;
char aa=a,bb=b,cc=c;
int sum=6;
x=sum-a-c;
sum-=x;
z=sum-c;
sum-=z;
y=sum;
printf("x with ")(x);
printf("y with ")(y);
printf("z with ")(z);
return 0;
}
int P(int m){
char a='a',b='b',c='c';
if(m==1)printf("%c\n",a);
else if(m==2)printf("%c\n",b);
else printf("%c\n",c);
return 0;
}

/*output:
x with b
y with c
z with a*/

/*2.*/
#include<stdio.h>
int main(void)
{
int time=2;
float sum=100,high=50;
for(;time<=10;time++){
sum+=2*high;
high=high/2;
}
printf("%f\n",sum);
return 0;
}

/*output:
299.609375*/

/*1.*/
#include<stdio.h>
int main(void)
{
int a=1,b=1;
int count=0;
for(;a<=1000;a++){
while(b<a){
if(a%b==0)count+=b;
b++;
}
if(a==count)printf("%d\n",a);
count=0;
b=1;
}
return 0;
}

/*output:
6
28
496*/
世间纷华不过一瞬执子之手难免抽离
回复 支持 反对

使用道具 举报

该用户从未签到

1

主题

0

好友

827

积分

New Game

积分
827
发表于 2013-5-4 18:54:18 | 显示全部楼层
可以先占楼的吧~~~趴下~~

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

点评

温馨提示:请抽时间来完善帖子撒 求完善 o(╯□╰)o  发表于 2013-5-14 09:34
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

本版积分规则

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

GMT+8, 2024-3-29 21:11 , Processed in 0.313207 second(s), 51 queries , Redis On.

Copyright © 2018 技术宅社区

Powered by Discuz! X3.5

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