Problem Statement
You are given NN strings S_1,S_2,\ldots,S_NS1,S2,…,SN in this order.
Print S_N,S_{N-1},\ldots,S_1SN,SN−1,…,S1 in this order.
Constraints
1\leq N \leq 101≤N≤10
NN is an integer.
S_iSi is a string of length between 11 and 1010, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.
Input
The input is given from Standard Input in the following format:
NNS_1S1S_2S2\vdots⋮S_NSN
Output
Print NN lines. The ii-th (1\leq i \leq N)(1≤i≤N) line should contain S_{N+1-i}SN+1−i.
Sample 1
Inputcopy | Outputcopy |
3 Takahashi Aoki Snuke | Snuke Aoki Takahashi |
We have N=3N=3, S_1=S1= Takahashi, S_2=S2= Aoki, and S_3=S3= Snuke.
Thus, you should print Snuke, Aoki, and Takahashi in this order.
Sample 2
Inputcopy | Outputcopy |
4 2023 Year New Happy | Happy New Year 2023 |
The given strings may contain digits.
题目大意是我们输入字符串,然后反向输出,这个我还是看的懂,后面的翻译根本看不懂了!!!哭晕,一个结构体轻松搞定
#include <stdio.h>
struct str
{
char arr[1000];
}s[100];
int main()
{
int i,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",s[i].arr);
}
for(i=n;i>=1;i--)
{
printf("%s\n",s[i].arr);
}
}
Problem Statement
In this problem, an input file contains multiple test cases.
You are first given an integer TT. Solve the following problem for TT test cases.
We have NN positive integers A_1, A_2, ..., A_NA1,A2,...,AN. How many of them are odd?
Constraints
1 \leq T \leq 1001≤T≤100
1 \leq N \leq 1001≤N≤100
1 \leq A_i \leq 10^91≤Ai≤109
All values in the input are integers.
Input
The input is given from Standard Input in the following format, where \text{test}_itesti represents the ii-th test case:
TT\text{test}_1test1\text{test}_2test2\vdots⋮\text{test}_TtestT
Each test case is in the following format:
NNA_1A1A_2A2\dots…A_NAN
Output
Print TT lines. The ii-th line should contain the answer for the ii-th test case.
Sample 1
Inputcopy | Outputcopy |
4 3 1 2 3 2 20 23 10 6 10 4 1 5 9 8 6 5 1 1 1000000000 | 2 1 5 0 |
This input contains four test cases.
The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3N=3,A1=1,A2=2,A3=3.
We have two odd numbers in A_1A1, A_2A2, and A_3A3, so the first line should contain 22.
题目的意思就是要我们找一串数字的奇数和偶数的数量,这个翻译就难懂了,我翻译出来我看都不懂,我就看案例
#include <stdio.h>
int main()
{
int t,n,x;
scanf("%d",&t);
while(t--)
{
int i,sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
if(x%2==1) sum++;
}
printf("%d\n",sum);
}
}
Problem Statement
You are given a simple undirected graph with NN vertices numbered 11 to NN and MM edges numbered 11 to MM. Edge ii connects vertex u_iui and vertex v_ivi.
Find the number of connected components in this graph.
Notes
A simple undirected graph is a graph that is simple and has undirected edges.
A graph is simple if and only if it has no self-loop or multi-edge.
A subgraph of a graph is a graph formed from some of the vertices and edges of that graph.
A graph is connected if and only if one can travel between every pair of vertices via edges.
A connected component is a connected subgraph that is not part of any larger connected subgraph.
Constraints
1 \leq N \leq 1001≤N≤100
0 \leq M \leq \frac{N(N - 1)}{2}0≤M≤2N(N−1)
1 \leq u_i, v_i \leq N1≤ui,vi≤N
The given graph is simple.
All values in the input are integers.
Input
The input is given from Standard Input in the following format:
NNMMu_1u1v_1v1u_2u2v_2v2\vdots⋮u_MuMv_MvM
Output
Print the answer.
Sample 1
Inputcopy | Outputcopy |
5 3 1 2 1 3 4 5 | 2 |
The given graph contains the following two connected components:
a subgraph formed from vertices 11, 22, 33, and edges 11, 22;
a subgraph formed from vertices 44, 55, and edge 33.
Sample 2
Inputcopy | Outputcopy |
5 0 | 5 |
Sample 3
Inputcopy | Outputcopy |
4 6 1 2 1 3 1 4 2 3 2 4 3 4 | 1 |
这道题目的意思就是有几个我们输入的集合,比如我们第一个样例,就是有两个我们的集合,我开始看那个翻译,我以为5 3是我们输入的是要连起来的!!!把我卡了半天!!!
这道题我们直接让点数-合并了多少次就是答案
#include <stdio.h>
int fa[100001];
int i;
void chushi(int n)
{
for(i=0;i<=n;i++)
{
fa[i]=i;
}
}
int find(int x)
{
if(fa[x]==x) return x;
else
{
fa[x]=find(fa[x]);
return fa[x];
}
}
void he(int a,int b)
{
fa[a]=b;
}
int main()
{
int n,m,ans=0;
int a,b;
scanf("%d%d",&n,&m);
chushi(n);
while(m--)
{
scanf("%d%d",&a,&b);
a=find(a);
b=find(b);
if(a!=b)
{
he(a,b);
ans++;
}
}
printf("%d\n",n-ans);
}
Define the score of some binary string TT as the absolute difference between the number of zeroes and ones in it. (for example, T=T= 010001 contains 44 zeroes and 22 ones, so the score of TT is |4-2| = 2∣4−2∣=2).
Define the creepiness of some binary string SS as the maximum score among all of its prefixes (for example, the creepiness of S=S= 01001 is equal to 22 because the score of the prefix S[1 \ldots 4]S[1…4] is 22 and the rest of the prefixes have a score of 22 or less).
Given two integers aa and bb, construct a binary string consisting of aa zeroes and bb ones with the minimum possible creepiness.
Input
The first line contains a single integer tt (1\le t\le 1000)(1≤t≤1000) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers aa and bb (1 \le a, b \le 1001≤a,b≤100) — the numbers of zeroes and ones correspondingly.
Output
For each test case, print a binary string consisting of aa zeroes and bb ones with the minimum possible creepiness. If there are multiple answers, print any of them.
Sample 1
Inputcopy | Outputcopy |
5 1 1 1 2 5 2 4 5 3 7 | 10 011 0011000 101010101 0001111111 |
Note
In the first test case, the score of S[1 \ldots 1]S[1…1] is 11, and the score of S[1 \ldots 2]S[1…2] is 00.
In the second test case, the minimum possible creepiness is 11 and one of the other answers is 101.
In the third test case, the minimum possible creepiness is 33 and one of the other answers is 0001100.
题目理解:这道题的意思是我们求出前缀长最小,就是10或者01这样子就ok
#include <stdio.h>
int main()
{
int n,i,a,b;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&a,&b);
while(a>=b)
{
if(a>0)
{
printf("0");
a--;
}
if(b>0)
{
printf("1");
b--;
}
if(a==b&&a==0) break;
}
while(a<b)
{
if(b>0)
{
printf("1");
b--;
}
if(a>0)
{
printf("0");
a--;
}
if(a==b&&b==0) break;
}
printf("\n");
}
}
下班下班,唐怡佳那小子盯着我交了没