首页 > 代码库 > codeforces——模拟

codeforces——模拟

805 B. 3-palindrome    http://codeforces.com/problemset/problem/805/B

技术分享
/*题意字符串中不能有长度为三的回文串,且c数量最少*/#include<iostream>#include<cstdio>#include<cstring>using namespace std;char s[4]={a,a,b,b};int n;int main(){    scanf("%d",&n);    for(int i=0;i<n;i++)      printf("%c",s[i%4]);    printf("\n");    return 0;}
View Code

807 A Is it rated?       http://codeforces.com/problemset/problem/807/A

技术分享
#include<iostream>#include<cstdio>#include<cstring>#define maxn 1001using namespace std;int n,m,cnt;int a[maxn],b[maxn];inline int init(){    int x=0,f=1;char c=getchar();    while(c>9||c<0){if(c==-)f=-1;c=getchar();}    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}    return x*f;}int main(){    n=init();    for(int i=1;i<=n;i++)    {        a[i]=init();b[i]=init();    }    for(int i=2;i<=n;i++)    {        if(a[i]!=b[i])        {            printf("rated\n");            return 0;        }        if(a[i]>a[i-1])        {            printf("unrated\n");            return 0;        }    }    printf("maybe\n");    return 0;}
View Code

错误代码

技术分享
#include<iostream>#include<cstdio>#include<cstring>#define maxn 1001using namespace std;int n,m,cnt;int a[maxn],b[maxn];inline int init(){    int x=0,f=1;char c=getchar();    while(c>9||c<0){if(c==-)f=-1;c=getchar();}    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}    return x*f;}int main(){    n=init();    for(int i=1;i<=n;i++)    {        a[i]=init();b[i]=init();    }    for(int i=2;i<=n;i++)    {        if(a[i]!=b[i])//这里!!可能第一个就不相同        {            printf("rated\n");            return 0;        }        if(a[i]>a[i-1])        {            printf("unrated\n");            return 0;        }    }    printf("maybe\n");    return 0;}
View Code

 

codeforces——模拟