| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
好无聊的题#include <stdio.h>
#include <string.h>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;
string fmt;
vector<string> vs;
void print(){
//cout << fmt << " " << vs.size() << endl;
string data[32][233];
int width = fmt.length();
int kuan[233] = {0};
int height = vs.size();
for(int i = 0; i < height; i++){
string tar = vs[i];
tar += '&';
int numOfAnd = 0;
int offset = 0;
while(numOfAnd < width){
int j = offset;
for(; ; j++){
if(tar[j] == '&') break;
}
data[i][numOfAnd] = tar.substr(offset, j-offset);
numOfAnd ++;
offset = j+1;
}
}
for(int i = 0; i < width; i++){
for(int j = 0; j < height; j++){
int ll = data[j][i].length();
if(ll > kuan[i]) kuan[i] = ll;
}
kuan[i] += 2;
}
cout << "@";
for(int i = 0; i < width; i++){
for(int j = 0; j < kuan[i]; j++) cout << "-";
if(i != width-1) cout << "-";
else cout << "@" << endl;
}
for(int i = 0; i < height; i++){
cout << "|";
for(int j = 0; j < width; j++){
int zuo, you;
int ll = data[i][j].length();
if(fmt[j] == '<'){
zuo = 1;
you = kuan[j] - 1 - ll;
}
else if(fmt[j] == '>'){
you = 1;
zuo = kuan[j] - 1 - ll;
}
else{
zuo = (kuan[j] - ll) / 2;
you = kuan[j] - ll - zuo;
}
for(int k = 0; k < zuo; k++) cout << " ";
cout << data[i][j];
for(int k = 0; k < you; k++) cout << " ";
cout << "|";
}
cout << endl;
if(!i){
cout << "|";
for(int t = 0; t < width; t++){
for(int j = 0; j < kuan[t]; j++) cout << "-";
if(t != width-1) cout << "+";
else cout << "|" << endl;
}
}
}
cout << "@";
for(int i = 0; i < width; i++){
for(int j = 0; j < kuan[i]; j++) cout << "-";
if(i != width-1) cout << "-";
else cout << "@" << endl;
}
}
int main(int argc, char **argv){
while(1){
string s;
while(1){
getline(cin, s);
if(s[0] == '<' || s[0] == '>' || s[0] == '=' || s[0] == '*') break;
vs.push_back(s);
}
if(fmt.length() > 0){
print();
}
fmt = s;
if(fmt[0] == '*') break;
vs.clear();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator