poj 3617 Best Cow Line

poj 3617 Best Cow Line,第1张

poj 3617 Best Cow Line
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 2008int n;char line[maxn];void input(){    scanf("%d", &n);    for (int i = 0; i < n; i++)    {        char ch[3];        scanf("%s", ch);        line[i] = ch[0];    }}void work(){    int l = 0, r = n - 1;    int ncount = 0;    while (l <= r)    {        int a = l, b = r;        while (a < b && line[a] == line[b]) a++, b--;        if (line[a] > line[b]) putchar(line[r--]);        else putchar(line[l++]);        ncount++;        if (ncount % 80 == 0) putchar('n');    }    if (ncount % 80)        putchar('n');}int main(){    input();    work();    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4917925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存