2.7总结

Problem Statement

You are given N strings 1,2,…,S1,S2,…,SN in this order.

Print SN,SN−1,…,S1 in this order.

Constraints

  • 1≤N≤10

  • N is an integer.

  • S1is a string of length between 1and 10, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.


Input

The input is given from Standard Input in the following format:

Output

代码如下:

#include<stdio.h>
#include<string.h>
struct edge
{
    char s[15];
}e[15];

int main()
{
    int N;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%s",e[i].s);
    for(int i=N;i>=1;i--)
        printf("%s\n",e[i].s);
        return 0;
}

代码如下:

#include<stdio.h>
int fun(int a[105],int m)
{
    int i,sum=0;
    for(i=0;i<m;i++)
    {
        if(a[i]%2!=0) sum=sum+1;
    }
    return sum;
}
main()
{
    int t,m,i;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        int j;
        int a[105]={0};
        scanf("%d",&m);
        for(j=0;j<m;j++)
        scanf("%d",&a[j]);
        printf("%d\n",fun(a,m));
    }
}

Directional Increase

We have an array of length n. Initially, each element is equal to 00 and there is a pointer located on the first element.

We can do the following two kinds of operations any number of times (possibly zero) in any order:

If the pointer is not on the last element, increase the element the pointer is currently on by 11. Then move it to the next element.

If the pointer is not on the first element, decrease the element the pointer is currently on by 11. Then move it to the previous element.

But there is one additional rule. After we are done, the pointer has to be on the first element.

You are given an array a. Determine whether it's possible to obtain a after some operations or not.

Input

The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤2⋅105) — the size of array a.

The second line of each test case contains n integers 1,2,…,a1,a2,…,an (−109≤ai≤109) — elements of the array.

It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅105.

Output

For each test case, print "Yes" (without quotes) if it's possible to obtain a after some operations, and "No" (without quotes) otherwise.

You can output "Yes" and "No" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

Note

In the first test case we can obtain the array after some operations, but the pointer won't be on the first element.

One way of obtaining the array in the second test case is shown below.

⟨0,0,0,0⟩→⟨1,0,0,0⟩→⟨1,−1,0,0⟩→⟨2,−1,0,0⟩→⟨2,0,0,0⟩→⟨2,0,−1,0⟩→⟨2,−1,−1,0⟩

代码如下:

#include<stdio.h>
#define MAX 200010
long long int a[MAX];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long int n,i,flag=0,flag1=0,count=0;
        scanf("%lld",&n);
        for(i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        for(i=1;i<=n;i++)
        {
            if(flag==1&&a[i]!=0)
            {
                printf("NO\n");
                flag1=1;
               break;
            }
            count+=a[i];
            if(count<=0)
                flag=1;
        }
        if(flag1==1)
           continue;
        if(count!=0)
            printf("NO\n");
        else
            printf("YEs\n");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值