A Piece of Cake

原文链接: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.

  1. Put calories into the mixing bowl.
  2. Take carrots from refrigerator.
  3. Chop carrots.
  4. Take chocolate spread from refrigerator.
  5. Put chocolate spread into the mixing bowl.
  6. Combine pack of flour into the mixing bowl.
  7. Fold chocolate spread into the mixing bowl.
  8. Add chocolate spread into the mixing bowl.
  9. Put pack of flour into the mixing bowl.
  10. Add egg into the mixing bowl.
  11. Fold pack of flour into the mixing bowl.
  12. Chop carrots until choped.
  13. 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;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值