#include<stdio.h>
#include<string.h>
int main()
{
    char a[51];
    int m,n,t,i,j;
    scanf("%d %d",&n,&t);
    scanf("%s",a);
    for(j=1;j<=t;j++)
    for(i=0;i<n-1;i++)
    {
        if(a[i]=='B'&&a[i+1]=='G'&&i+1<n)
        {
            m=a[i];
            a[i]=a[i+1];
            a[i+1]=m;
            i+=1;
        }
    }
    printf("%s",a);
    return 0;
}
http://codeforces.com/contest/266/problem/B
#include<stdio.h>
#include<string.h>
int main()
{
    char a[51];
    int m,n,t,i,j;
    scanf("%d %d",&n,&t);
    scanf("%s",a);
    for(j=1;j<=t;j++)
    for(i=0;i<n-1;i++)
    {
        if(a[i]=='B'&&a[i+1]=='G'&&i+1<n)
        {
            m=a[i];
            a[i]=a[i+1];
            a[i+1]=m;
            i+=1;
        }
    }
    printf("%s",a);
    return 0;
}

http://codeforces.com/contest/266/problem/B

posted on 2013-01-23 12:22  海暗  阅读(233)  评论(0编辑  收藏  举报