zoukankan      html  css  js  c++  java
  • 进阶之路

    进阶之路

    Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)




    C-source:
     1  1 #include<stdio.h>
     2  2 int main()
     3  3 {
     4  4     int num;
     5  5     printf("Please input the num:
    ");
     6  6     scanf("%d",&num);
     7  7 
     8  8     int *array=(int*)malloc(num*sizeof(int));
     9  9     int *answer=(int*)malloc(num*sizeof(int));
    10 10 
    11 11     int i,j,k;
    12 12     for(i=0;i<num;i++)
    13 13         scanf("%d",&array[i]);
    14 14 
    15 15     printf("
    ");
    16 16 
    17 17     for(i=0;i<num;i++)
    18 18         answer[i]=0;
    19 19 
    20 20     printf("
    ");
    21 21     int temp;
    22 22     for(i=0;i<num;i++)
    23 23     {
    24 24         temp=0;
    25 25         if(array[i]%2==0)
    26 26         {
    27 27             temp=array[i]/2;
    28 28             answer[i]=2;
    29 29 
    30 30             int *s=(int*)malloc((temp-1)*sizeof(int));
    31 31 
    32 32             for(j=0;j<temp-1;j++)
    33 33             {
    34 34                 s[j]=array[i]-(j+1);
    35 35                 answer[i]+=s[j];
    36 36             }
    37 37             printf("%d
    ",answer[i]);
    38 38         }
    39 39         else
    40 40         {
    41 41             temp=array[i]/2;
    42 42             answer[i]=1;
    43 43 
    44 44             int *t=(int*)malloc(temp*sizeof(int));
    45 45 
    46 46             for(j=0;j<temp;j++)
    47 47             {
    48 48                 t[j]=array[i]-(j+1);
    49 49                 answer[i]+=t[j];
    50 50             }
    51 51             printf("%d
    ",answer[i]);
    52 52         }
    53 53     }
    54 54     return 0;
    55 55 }
     
  • 相关阅读:
    《将博客搬至CSDN》
    2015-05-01 至 2015-07-30错误总结
    2015-01-01至2015-04-30错误积累
    2015-07-30 至 2016-03-16错误Note
    2014-11-21错误总结
    Spring 和 SpringMVC 的区别
    spring 容器加载
    Spring注解
    自定义拦截器
    Js闭包
  • 原文地址:https://www.cnblogs.com/vpoet/p/4659762.html
Copyright © 2011-2022 走看看