[Codeforces Round #163 (Div. 2)]B. Queue at the School

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

时间一秒一秒的减,没有人换位或是时间到就停止

#include<stdio.h>

int n,t;
char in[55];

int main()
{
    int i,flag=0;
    scanf("%d %d",&n,&t);
    scanf("%s",in);
    while(t>0)
    {
        flag=0;
        for(i=0;i<n-1;)
        {
            if(in[i]=='B' && in[i+1]=='G')
            {
                in[i]='G';
                in[i+1]='B';
                i=i+2;
                flag=1;
            }
            else
            {
                i++;
            }
        }
        if(flag) t--;
        else break;
    }
    printf("%s\n",in);
    return 0;
}

 

posted @ 2013-01-23 15:22  tjsuhst  阅读(167)  评论(0)    收藏  举报