ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ /* 时间: 20120314 作者: 烟大洋仔 问题: Problem DescriptionYour task is to Calculate the sum of some integers. InputInput contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed. OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input. Sample Input4 1 2 3 45 1 2 3 4 50 Sample Output1015 解析: 该题目主要是要控制输入数据的个数,通过while进行控制输入的数据并 且判断 程序是不是应该结束; 第二个while语句为控制输入数据的个数,并且计算出要求得和 ; 第一遍的时候出现了错误; 因为sum在第二次计算之前没有清零!!!!这点很重要 */ #include <iostream> using namespace std; int main() { int n,a,sum=0; while(cin>>n&&n!=0) { while (n--) { cin>>a; sum=sum+a; } cout<<sum<<endl; sum=0; } return 0; } ~~~