acm 杭电-杭州电子科技大学 acm 第1001题

问题描述

杭州电子科技大学 acm 第1001题
题目的输入要求是The input will consist of a series of integers n one integer per line.输出要求是For each case output SUM(n) in one line followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.我提交的答案总是Runtime Error(ACCESS_VIOLATION).我想知道我写的代码怎么改是正确的,谢了(下面是我的代码)我的想法是一次输入一些数,然后用数组存起来,然后求和后再按行输出。

include
define LEN 20
int main()
{

int in[LEN];

int i = 0 ;

int j;

int n;

while(scanf(""%d""&n) != EOF)

{

in[i] = n;//用数组来存储每次输入的n的值
i++;

}

for(j = 0; (j < i) && (in[j] < 65536); j++)//in[j]<65536防止最后的结果超过要求的有符号32位的值

{

printf(""%dnn"" (in[j]%2) ? (((in[j]+1)/2)* in[j]) : ((in[j]/2)*(1+ in[j]))); //按照输入的n的值的顺序求值

}
}

时间: 2024-08-18 02:47:56

acm 杭电-杭州电子科技大学 acm 第1001题的相关文章

acm 杭电-long long 的运行时间比int长吗?

问题描述 long long 的运行时间比int长吗? 杭电中,数据定义为long long 后, 运行的时间比int长,(hud 1597)结果导致程序超时.为什么?

ACM杭电1001 Sum Problem 为什么会报错Compilation Error

问题描述 importjava.util.Scanner;publicclassSumProblem{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);while(sc.hasNext()){intsum=0;inti=sc.nextInt();for(intj=1;j<=i;j++){sum+=j;}System.out.println(sum);}}} 解决方案 解决方案二:运行没问题呀解决方案三:你是说在本

杭电 acm 2039 ( 三角形 )判断这样用问什么会通不过呢?哪位大神讲讲正确的用法

问题描述 杭电 acm 2039 ( 三角形 )判断这样用问什么会通不过呢?哪位大神讲讲正确的用法 三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 28002 Accepted Submission(s): 9138 Problem Description 给定三条边,请你判断一下能不能组成一个三角形. Input 输入数据第一行包含

杭电ACM 2000-&amp;gt;2099 100道题 详细解题报告出炉

我去年暑假花了5天,把杭电ACM网站上2000到2099这100道题全AC了,又花了10来天精心写解题报告.里面包括题目.解题思路.编程技巧以及参考源码.所有代码都是使用C/C++写的. 最近整理资料时无意间发现,打包成chm文件和大家分享.我已经上传到CSDN上了.下载地址:http://download.csdn.net/source/492194 也可到我的Google Sites上下载. 题号 题名 题号 题名 2000 ASCII码排序 2001 计算两点间的距离 2002 计算球体积

杭电acm n的阶乘 大数-杭电ACM 1042 N的阶乘 大数 问题在我注释的地方

问题描述 杭电ACM 1042 N的阶乘 大数 问题在我注释的地方 #include #include int c[10086]; int main() { int i,j,l,n,k,h; while(scanf("%d",&n)!=EOF) { memset(c,0,sizeof(c)); c[0]=1; k=0; if(n==0) printf("1n"); else { for(j=1;j<=n;j++) { for(i=0;i<=k;i

杭电1002

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 #include <stdio.h> #include <string.h> #define MAX 1010 char a[MAX],b[MAX]; int main() { int n,i,j,length,jinwei=0; int flag; char temp; scanf("%d",&n); for(i=0;i<n;i++) { i

acm-关于杭电ACM2031 进制转换感觉找不出自己的错误,求指出

问题描述 关于杭电ACM2031 进制转换感觉找不出自己的错误,求指出 #includeint main(){ long nr; char a[10000]; while(scanf(""%d%d""&n&r) == 2) { if(n == 0) printf(""0 ""); else { int i = 0; if(n while(n > 0) { a[i++] = n%r; n=n/r; } in

c++中qsort函数自定义比较函数的问题(杭电1009)

问题描述 c++中qsort函数自定义比较函数的问题(杭电1009) #include<iostream> #include<iomanip> #include<stdlib.h> #include<stdio.h> #include<algorithm> using namespace std; struct room { double amount,l; int number; }; int comp(const void *x,const

杭电oj第一题居然一直过不了

问题描述 杭电oj第一题居然一直过不了 #include "stdio.h" int main() { int a,b; scanf("%d%d",&a,&b); printf("%d ",a+b); return 0; } 运行不是好好的吗,怎么总是过不了 解决方案 杭电OJ第十五届ACM第一题 Hearthstone杭电第一题 解决方案二: 检查一下自己的输入输出格式 解决方案三: (a+b)呢,....