Educational Codeforces Round 14

来源:互联网 发布:剑灵捏脸数据怎么下载 编辑:程序博客网 时间:2024/06/15 21:42

A. Fashion in Berland
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.

You are given a jacket with n buttons. Determine if it is fastened in a right way.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.

The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.

Output

In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".

Examples
input
31 0 1
output
YES
input
31 0 0
output
NO

#include <bits/stdc++.h>using namespace std;int main(){    int n,a[1005];    scanf("%d",&n);    int ans=0;    for(int i=0;i<n;i++)    {        scanf("%d",&a[i]);        if(a[i]==1)            ans++;    }    if(n==1)    {        if(ans==1)            printf("YES\n");        else printf("NO\n");    }    else if(ans!=n-1)        printf("NO\n");    else printf("YES\n");    return 0;}

B. s-palindrome
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.

English alphabet

You are given a string s. Check if the string is "s-palindrome".

Input

The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.

Output

Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.

Examples
input
oXoxoXo
output
TAK
input
bod
output
TAK
input
ER
output
NIE

#include <bits/stdc++.h>using namespace std;int main(){    string s;    cin>>s;    int len=s.size();    char c[19][2]={'A','A','b','d','d','b','H','H','I','I','M','M','O','O','o',    'o','p','q','q','p','U','U','V','V','v','v','W','W','w','w','X','X','x','x','Y','Y','T','T'};    int flag=0;    for(int i=0;i<=len/2;i++)    {        int fg=0;        for(int j=0;j<19;j++)        {            if(s[i]==c[j][0]&&s[len-i-1]==c[j][1])            {                fg=1;                break;            }        }        if(fg==0)        {            puts("NIE");            flag=1;            break;        }    }    if(flag==0) puts("TAK");    return 0;}

C. Exponential notation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a positive decimal number x.

Your task is to convert it to the "simple exponential notation".

Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in aand b.

Input

The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.

Output

Print the only line — the "simple exponential notation" of the given number x.

Examples
input
16
output
1.6E1
input
01.23400
output
1.234
input
.100
output
1E-1
input
100.
output
1E2

A,B题感觉纯粹考你能不能读懂题,C题稍微有点意思,让我认识到了我好像真的没有学过C++,下面这个是我的代码

#include<bits/stdc++.h>using namespace std;const int M=1e6+6;char a[M];int main(){    string s;    cin>>s;    queue<char>q;    int x=0;    for(int i=0;i<s.size();i++)    {        if(s[i]!='0')        {            x=i;            break;        }    }    for(int i=x;i<s.size();i++)    {        q.push(s[i]);    }    int cnt=0,b=0;    if(q.front()=='.')    {        q.pop();        while(q.front()=='0')        {            q.pop();            b--;        }        a[cnt++]=q.front();        q.pop();        a[cnt++]='.';        b--;        while(!q.empty())        {            a[cnt++]=q.front();            q.pop();        }    }    else    {        a[cnt++]=q.front();        q.pop();        a[cnt++]='.';        while(q.front()!='.'&&!q.empty())        {            a[cnt++]=q.front();            q.pop();            b++;        }        if(q.front()=='.')            q.pop();        while(!q.empty())        {            a[cnt++]=q.front();            q.pop();        }    }    int len=strlen(a);    while(a[len-1]=='0'||a[len-1]=='.') len--;    for(int i=0;i<len;i++)        printf("%c",a[i]);    if(b!=0)        printf("E%d\n",b);    return 0;}


这个是大神kondranin的代码,突然发现原来string还有这么多可以用的函数。。。。。。。。。。。。。。。涨姿势了
int main(){    string s;    cin >> s;    int pos = s.find('.');    if (pos != -1) {        s.erase(pos, 1);    } else {        pos = s.size();    }    int pos2 = 0;    for (int i=0; i<s.size(); i++) {        if (s[i] > '0') {            pos2 = i;            break;        }    }    int e = pos - pos2 - 1;    s.erase(0, pos2);    while (s.size() > 1 && s.back() == '0') {        s.pop_back();    }    if (s.size() >= 2) {        s.insert(1, ".");    }    if (e == 0) {        cout << s << endl;    } else {        cout << s << "E" << e << endl;    }}


0 0