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:
![](https://i-blog.csdnimg.cn/blog_migrate/752551acc0985b7517604076200f4cdf.png)
Output
![](https://i-blog.csdnimg.cn/blog_migrate/5893eeb6b91303da9fdb1808e0372008.png)
代码如下:
#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;
}
![](https://i-blog.csdnimg.cn/blog_migrate/696ea7db7aee34f870774f2e51ef7f25.png)
![](https://i-blog.csdnimg.cn/blog_migrate/98b738e464f1c47eaec0a3cfb633bc18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d3a9249b829e6aec907d2a68f7f11c39.png)
代码如下:
#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");
}
}