1194 -- 爱走楼梯的小胖

来源:互联网 发布:谷歌学术镜像 知乎 编辑:程序博客网 时间:2024/04/29 16:10

爱走楼梯的小胖

Time Limit:1000MS  Memory Limit:65536K
Total Submit:30 Accepted:25

Description

 小胖最喜欢的活动是走楼梯!所以他每次去实验室总会坐电梯随机到一个楼层,然后走楼梯到实验室所在的楼层,并为此得意不已。现在的问题来了,已经知道每两层楼之间的楼梯级数、小胖坐电梯要到达的楼层、实验室所在楼层,那么小胖每次得走多少级楼梯才能到达实验室?

Input

输入数据的第一行是一个正整数T(0<T≤100),表示有T组测试数据。
每组测试数据有两行:第一行为三个整数N, A, B(0<N≤100, 0<A, B≤N),表示有N层楼,小胖坐电梯到的楼层A,实验室所在楼层为B;第二行包括N–1个整数,其中第i个整数代表从第i层到第i + 1层之间的楼梯级数Si(0<Si≤100)。

Output

对于每组测试数据,在一行上输出一个整数P,表示小胖到实验室所在楼层需要走P级楼梯。

Sample Input

36 1 510 10 10 10 106 5 110 10 10 10 1010 3 71 2 3 4 5 6 7 8 9

Sample Output

404018

Source

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1194 {    class Program {        static void Main(string[] args) {            int t = int.Parse(Console.ReadLine());            while (t-- > 0) {                string[] s = Console.ReadLine().Split();                int n = int.Parse(s[0]), a = int.Parse(s[1]), b = int.Parse(s[2]);                int[] ans = new int[105];                string[] sb = Console.ReadLine().Split();                for (int i = 1; i < n; i++)                    ans[i] = int.Parse(sb[i-1]);                int sum = 0;                if (a > b) { int temp = a; a = b; b = temp; }                for (int i = a; i < b; i++)                    sum += ans[i];                Console.WriteLine(sum);            }        }    }}


0 0
原创粉丝点击