Codeforces Round 918 (Div. 4)

目录

A. Odd One Out

Input

Output

题意翻译

Example

代码展示

B. Not Quite Latin Square

Input

Output

题意翻译

Example

代码展示

C. Can I Square?

Input

Output

题意翻译

Example

代码展示

D. Unnatural Language Processing

Input

Output

题意翻译

输入

输出

Example

代码展示


A. Odd One Out

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

You are given three digits a, b, c. Two of them are equal, but the third one is different from the other two.

Find the value that occurs exactly once.

Input

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

The only line of each test case contains three digits a , b , c ( 0≤a,b,c≤9 ). Two of the digits are equal, but the third one is different from the other two.

Output

For each test case, output the value that occurs exactly once.

题意翻译

t 组数据。每次给出三个数字 a,b,c,其中有两个数字是相等的,输出那个不相等的数字。

Example

input

10
1 2 2
4 3 4
5 5 6
7 8 8
9 0 9
3 6 3
2 8 2
5 7 7
7 7 5
5 7 5

output

1
3
6
7
0
6
8
5
5
7

代码展示

#include<bits/stdc++.h>
using namespace std;
int main()        //无特殊技巧
{
    int n;
    cin>>n;
    int a,b,c;
    while(n--)
    {
        cin>>a>>b>>c;
        if(a==b) cout<<c<<endl;
        else if(a==c) cout<<b<<endl;
        else cout<<a<<endl;
    }
    return 0;
}

B. Not Quite Latin Square

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

A Latin square is a 3×33×3 grid made up of the letters A, B, and C such that:

  • in each row, the letters A, B, and C each appear once, and
  • in each column, the letters A, B, and C each appear once.

For example, one possible Latin square is shown below.

\begin{Bmatrix} A & B & C\\ C& A &B \\ B & C & A \end{Bmatrix}

You are given a Latin square, but one of the letters was replaced with a question mark ?. Find the letter that was replaced.

Input

The first line of the input contains a single integer t (1≤t≤108) — the number of testcases.

Each test case contains three lines, each consisting of three characters, representing the Latin square. Each character is one of A, B, C, or ?.

Each test case is a Latin square with exactly one of the letters replaced with a question mark ?.

Output

For each test case, output the letter that was replaced.

题意翻译

t 组数据。每次给出一个由 A B C 组成的 3×33×3 的矩阵,矩阵满足的条件为:每行每列有且仅有各 11 个 A B C现在有一个字符被替换成了 ?,求出 ? 代表的字符。

Example

input

3
ABC
C?B
BCA
BCA
CA?
ABC
?AB
BCA
ABC

output

A
B
C

代码展示

#include<bits/stdc++.h>
using namespace std;
int main()        //纯暴力看是否A B C到达了三个哪个没有就输出哪个
{
    int n;
    cin>>n;
    char c[3][3];
    while(n--)
    {
        for(int i=0;i<3;i++)
        {
            cin>>c[i][0]>>c[i][1]>>c[i][2];
        }
        int a[3]={0};
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            if(c[i][j]=='A') a[0]++;
            else if(c[i][j]=='B') a[1]++;
            else a[2]++;
        }
        if(a[0]!=3) cout<<"A"<<endl;
        else if(a[1]!=3) cout<<"B"<<endl;
        else cout<<"C"<<endl;
    }
    return 0;
}

C. Can I Square?

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

Calin has n buckets, the i-th of which contains a_{i} wooden squares of side length 1.

Can Calin build a square using all the given squares?

Input

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

The first line of each test case contains a single integer n (1\leq n\leq 2*10^{5}) — the number of buckets.

The second line of each test case contains n integers a_{1},…,a_{n}(1≤a_{i}≤109) — the number of squares in each bucket.

The sum of n over all test cases does not exceed 2*10^{5}.

Output

For each test case, output "YES" if Calin can build a square using all of the given 1×11×1 squares, and "NO" otherwise.

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

题意翻译

t 组数据。每次给出 个整数 a_{1},a_{2},…,a_{n}。判断这 n 个数的和是否为完全平方数。

Example

input

5
1
9
2
14 2
7
1 2 3 4 5 6 7
6
1 3 5 7 9 11
4
2 2 2 2

output

YES
YES
NO
YES
NO

代码展示

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        int sum=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            int a;
            cin>>a;
            sum+=a;    //让所有数组里的数加起来,然后再判断是否是平方数。
        }
        int m=sqrt(sum);    //这里不能直接判断sqrt(sum)*sqrt(sum)==sum否则会WA
        if(m*m==sum) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

D. Unnatural Language Processing

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

Lura was bored and decided to make a simple language using the five letters a , b , c , d , e . There are two types of letters:

  • vowels — the letters a and e . They are represented by V .
  • consonants — the letters b , c , and d . They are represented by C .

There are two types of syllables in the language: CV (consonant followed by vowel) or CVCCVC (vowel with consonant before and after). For example, baced bab are syllables, but aaeda , baba are not.A word in the language is a sequence of syllables. Lura has written a word in the language, but she doesn't know how to split it into syllables. Help her break the word into syllables.

For example, given the word bacedbab , it would be split into syllables as ba.ced.bab (the dot .. represents a syllable boundary).

Input

The input consists of multiple test cases. The first line contains an integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (1\leq n\leq 2*10^{5}) — the length of the word.

The second line of each test case contains a string consisting of n lowercase Latin characters  — the word.

All words given are valid words in the language; that is, they only use the letters a, b, c, d, e, and each word is made up of several syllables.

The sum of n over all test cases does not exceed 2*10^{5}.

Output

For test case, output a string denoting the word split into syllables by inserting a dot .. between every pair of adjacent syllables.

If there are multiple possible splittings, output any of them. The input is given in such a way that at least one possible splitting exists.

题意翻译

卢拉觉得无聊,决定用五个字母 a 、 b 、 c 、 d 、e 制作一种简单的语言。字母有两种:

  • 元音--字母 a 和 e 。它们用 V 表示。
  • 辅音--字母 b 、 c 和 d 。用 C 表示。

该语言有两种音节: CV(辅音后有元音)或 CVC(元音前后有辅音)。例如, ba、 ced 、 bab 是音节,但 aa 、 eda 、 baba 不是。

语言中的单词是一串音节。Lura 用语言写了一个单词,但她不知道如何将其拆分成音节。帮她把这个词拆成音节。

例如,给定单词 bacedbab ,它可以拆分成 ba.ced.bab 音节。(点 .. 代表音节边界)。

输入

输入由多个测试用例组成。第一行包含一个整数 t (1≤t≤100) 测试用例的数量。测试用例说明如下。

每个测试用例的第一行包含一个整数 n (1\leq n\leq 2*10^{5}) - 词的长度。

每个测试用例的第二行包含一个由 n 个小写拉丁字符组成的字符串--单词。

给出的所有单词都是有效的语言单词;也就是说,它们只使用字母 a 、 b 、 c 、 d 、 e ,并且每个单词都由多个音节组成。

所有测试用例的 之和不超过 2*10^{5} 。

输出

对于测试用例,输出一个字符串,表示通过在每对相邻音节之间插入一个点 .. 将单词拆分成音节。

如果存在多种可能的拆分,则输出其中任何一种。输入保证至少存在一种可能的拆分。

Example

input

6
8
bacedbab
4
baba
13
daddecabeddad
3
dac
6
dacdac
22
dababbabababbabbababba

output

ba.ced.bab
ba.ba
dad.de.ca.bed.dad
dac
dac.dac
da.bab.ba.ba.bab.bab.ba.bab.ba

代码展示

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int t;
    cin>>t;
    string s1;
    while(t--)
    {
        int c[200100]={0};//每次循环刚开始时将数组归0.
        int n;
        cin>>n;
        cin>>s1;
        for(int i=0;i<n;i++)
        {
            if(s1[i]=='a'||s1[i]=='e') c[i]=2;//当为元音时该下标为2,否则为1.
            else c[i]=1;
        }
        for(int i=0;i<n;i++)
        {
            cout<<s1[i];    
            if(c[i+2]==2) cout<<'.';    //由CV和CVC可知当一个下标数+2为2时就该分开了。
        }
        cout<<endl;
    }
    return 0;
}

未完待续.......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值