codeforces-#475A. Bayan Bus(模拟)

来源:互联网 发布:淘宝 寄海外 编辑:程序博客网 时间:2024/04/29 06:13

           题目大意:给一个矩形的大巴乘坐规则,给定人数,输出大巴的座位的情况。

           解题思路:就是字符串模拟,可以对特殊的简单处理下,这里给出两种写法,第二种写法更直接,简单粗暴。详见code。

           题目大意:http://codeforces.com/problemset/problem/475/A

          code:

<pre name="code" class="cpp">#include <iostream>#include <cstdio>#include <cstring>using namespace std;int n,k,m;char str[4][27]={    "|#.#.#.#.#.#.#.#.#.#.#.|D|",    "|#.#.#.#.#.#.#.#.#.#.#.|.|",    "|#.......................|",    "|#.#.#.#.#.#.#.#.#.#.#.|.|",};int main(){    //freopen("input.txt","r",stdin);    while(~scanf("%d",&k)){        if(k>34) break;        printf("+------------------------+\n");        if(k<=4) for(int i=0;i<k;++i)            str[i][1]='O';        else if(k>4){            for(int i=0;i<4;++i)                str[i][1]='O';            k-=4;            n=k/3;            m=k%3;            for(int i=0;i<4;++i)                for(int j=0;j<n;++j)                    if(i!=2)str[i][3+2*j]='O';            for(int i=0;i<m;++i)                if(i!=2)str[i][2*n+3]='O';        }        for(int i=0;i<4;++i){            for(int j=0;j<26;++j)                printf("%c",str[i][j]);            if(i==0 || i==3)printf(")\n");            else printf("\n");        }        printf("+------------------------+\n");    }    return 0;}

     暴力code:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int k;char str[6][30]={    "+------------------------+",    "|#.#.#.#.#.#.#.#.#.#.#.|D|)",    "|#.#.#.#.#.#.#.#.#.#.#.|.|",    "|#.......................|",    "|#.#.#.#.#.#.#.#.#.#.#.|.|)",    "+------------------------+",};int main(){    scanf("%d",&k);    for(int i=0;i<30;++i)        for(int j=0;j<6;++j){            if(k==0) break;            if(str[j][i]=='#'){                k--;                str[j][i]='O';            }        }    for(int i=0;i<6;++i)        printf("%s\n",str[i]);    return 0;}

0 0
原创粉丝点击