原文链接:A Piece of Cake - 洛谷
题目描述
How to make a cake you'll never eat.
Ingredients.
- 2 carrots
- 0 calories
- 100 g chocolate spread
- 1 pack of flour
- 1 egg
Method.
- Put calories into the mixing bowl.
- Take carrots from refrigerator.
- Chop carrots.
- Take chocolate spread from refrigerator.
- Put chocolate spread into the mixing bowl.
- Combine pack of flour into the mixing bowl.
- Fold chocolate spread into the mixing bowl.
- Add chocolate spread into the mixing bowl.
- Put pack of flour into the mixing bowl.
- Add egg into the mixing bowl.
- Fold pack of flour into the mixing bowl.
- Chop carrots until choped.
- Pour contents of the mixing bowl into the baking dish.
Serves 1.
输入格式
The only line of input contains a sequence of integers a_{0},a_{1},...a0,a1,... ( 1<=a_{0}<=1001<=a0<=100 , 0<=a_{i}<=10000<=ai<=1000 for i>=1i>=1 ).
输出格式
Output a single integer.
题意翻译
输入:第一个整数是a[0]。之后a[0]个整数a[1],a[2],......,a[a[0]], 输出:一个整数=a[1] + 2 x a[2] + 3 x a[3] + ...... + a[0] x a[a[0]], a[0]<=100,a[i]<=1000
解题思路:
题目大意为:输入m个数字,然后按照输入顺序以1*m1+2*m2+3*m3.......+m*mm格式求出结果。
代码:
#include <stdio.h>
int main()
{
int m,i,sum=0;
scanf("%d",&m);
int a[m];
for(i=0;i<m;i++){
scanf("%d",&a[i]);
}
for(i=0;i<m;i++){
sum+=(i+1)*a[i];
}
printf("%d",sum);
return 0;
}