栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1578 Instruens Fabulam

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1578 Instruens Fabulam

#include <iostream>#include <string>using namespace std;const    int        maxlength = 2001, maxl = 100, maxc = 30;string    header, nextheader, word[maxl][maxc];int        lnum, cnum, csize[maxc];void init(){    string    st;    int        l = 0, c = 0, i;    memset(csize, 0, sizeof(csize));    cnum = header.length();    while (1)    {        getline(cin, nextheader);        if (nextheader[0] == '>' || nextheader[0] == '<' || nextheader[0] == '=' || nextheader[0] == '*') break;        for (i = 0; i < cnum - 1; i++)        { word[l][i] = nextheader.substr(0, nextheader.find("&")); nextheader.erase(0, nextheader.find("&") + 1); if (int(word[l][i].length()) > csize[i])     csize[i] = word[l][i].length();        }        word[l][cnum - 1] = nextheader;        if (int(word[l][cnum - 1].length()) > csize[cnum - 1]) csize[cnum - 1] = word[l][cnum - 1].length();        l++;    }    lnum = l;}void printl(int w, string st){    int        i, l = w - st.length();    cout << st;    for (i = 0; i < l; i++)        cout << " ";}void printc(int w, string st){    int        i, l = w - st.length();    for (i = 0; i < l / 2; i++)        cout << " ";    cout << st;    for (i = 0; i < l / 2; i++)        cout << " ";    if (l % 2 != 0)        cout << " ";}void printr(int w, string st){    int        i, l = w - st.length();    for (i = 0; i < l; i++)        cout << " ";    cout << st;}void printword(int i, string st){    switch (header[i])    {        case    '<': printl(csize[i], st); break;        case    '=': printc(csize[i], st); break;        case    '>': printr(csize[i], st); break;    }}void print(){    int        i, j;    //first line    cout << "@-";    for (i = 0; i < cnum - 1; i++)    {        for (j = 0; j < csize[i]; j++) cout << "-";        cout << "---";    }    for (j = 0; j < csize[cnum - 1]; j++)        cout << "-";    cout << "-@";    cout << endl;    //second line    cout << "|";    for (i = 0; i < cnum; i++)    {        cout << " ";        printword(i, word[0][i]);        cout << " |";    }    cout << endl;    //third line    cout << "|-";    for (i = 0; i < cnum - 1; i++)    {        for (j = 0; j < csize[i]; j++) cout << "-";        cout << "-+-";    }    for (j = 0; j < csize[cnum - 1]; j++)        cout << "-";    cout << "-|";    cout << endl;    //other lines    for (j = 1; j < lnum; j++)    {        cout << "|";        for (i = 0; i < cnum; i++)        { cout << " "; printword(i, word[j][i]); cout << " |";        }        cout << endl;    }    //last line    cout << "@-";    for (i = 0; i < cnum - 1; i++)    {        for (j = 0; j < csize[i]; j++) cout << "-";        cout << "---";    }    for (j = 0; j < csize[cnum - 1]; j++)        cout << "-";    cout << "-@";    cout << endl;}int main(){    getline(cin, header);    while (header[0] != '*')    {        init();        print();        header = nextheader;    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378599.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号