[Codeforces]Coder-Strike 2014 - Round 1

A.Poster

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char s[110];

int main()
{
    int n,k;

    scanf ("%d%d",&n,&k);
    scanf ("%s",s);
    int len = strlen (s);

    if (k > n / 2)
    {

        while (k < n)
        {
            printf ("RIGHT\n");
            k++;
        }
        k--;

        while (k != 0)
        {
            printf ("PRINT %c\n",s[k]);
            printf ("LEFT\n");
            k--;
        }
        printf ("PRINT %c\n",s[k]);
    }
    else
    {
        while (k > 1)
        {
            printf ("LEFT\n");
            k--;
        }
        k--;
        while (k != n - 1)
        {
            printf ("PRINT %c\n",s[k]);
            printf ("RIGHT\n");
            k++;
        }
        printf ("PRINT %c\n",s[k]);
    }
    return 0;
}


 

B. Network Configuration

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int num[1000];

int qp(int *left,int *right)
{
    int *l,*r;
    int k;
    if (left >= right)
        return 0;
    l = left;
    r = right;
    k = *left;

    while (l < r)
    {
        while (*r <= k && r > l)
            r--;
        *l = *r;

        while (*l >= k && l < r)
            l++;
        *r = *l;
    }
    *r = k;
    qp(left,r - 1);
    qp(l + 1,right);
}


int main()
{
    int n,k;

    scanf ("%d%d",&n,&k);

    for (int i = 0;i < n;i++)
        scanf ("%d",&num[i]);

    qp(num,&num[n - 1]);

    printf ("%d\n",num[k - 1]);

    return 0;
}


 

C. Pattern

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char s1[100001],s2[100001];
int bj[100001] = {0};

int main()
{
    int n;

    scanf ("%d",&n);

    scanf ("%s",s1);
    char *p1,*p2;
    int *p3;
    while (--n)
    {
        scanf ("%s",s2);
        p1 = s1;
        p2 = s2;
        p3 = bj;
        while (*p1 != '\0')
        {
            if (*p1 == '?')
            {
                if (*p2 != '?' && *p3 == 0)
                {
                    *p1 = *p2;
                }
            }else
            {
                if (*p2 != '?' && *p1 != *p2)
                {
                    *p1 = '?';
                    *p3 = 1;
                }
            }
            p1++;
            p2++;
            p3++;
        }
    }
        p1 = s1;
        p3 = bj;
        while (*p1 != '\0')
        {
            if (*p1 == '?' && *p3 == 0)
                *p1 = 'a';
            p1++;
            p3++;
        }

    printf ("%s\n",s1);
    return 0;
}


碰巧前三个都是模拟题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值