本文主要是介绍ACM从零开始---电子科大POJ 进阶之路,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
进阶之路
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
C-source:
#include<stdio.h>
int main()
{int num;printf("Please input the num:\n");scanf("%d",&num);int *array=(int*)malloc(num*sizeof(int));int *answer=(int*)malloc(num*sizeof(int));int i,j,k;for(i=0;i<num;i++)scanf("%d",&array[i]);printf("\n");for(i=0;i<num;i++)answer[i]=0;printf("\n");int temp;for(i=0;i<num;i++){temp=0;if(array[i]%2==0){temp=array[i]/2;answer[i]=2;int *s=(int*)malloc((temp-1)*sizeof(int));for(j=0;j<temp-1;j++){s[j]=array[i]-(j+1);answer[i]+=s[j];}printf("%d\n",answer[i]);}else{temp=array[i]/2;answer[i]=1;int *t=(int*)malloc(temp*sizeof(int));for(j=0;j<temp;j++){t[j]=array[i]-(j+1);answer[i]+=t[j];}printf("%d\n",answer[i]);}}return 0;
}
转载请注明作者:小刘
这篇关于ACM从零开始---电子科大POJ 进阶之路的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!