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 |
我认输,我连char talbe出现"*"都考虑了还过不了,哪位大大救救我,哭求(附程序)#include<iostream> #include<vector> #include<map> #include<string> #include<sstream> using namespace std; int curfont; int l, w; int cursize; int spacesize; int spacefont; int fontsize; int trailing; string first; string last; bool islast; int linecnt; int curw = 0; int curl = 1; int tempwidth; int pcnt; map<char, vector<int> > chartable; int getwidth(char c) { int unit; if(c == ' ') { unit = chartable[c].at(spacefont -1); unit = unit * spacesize * 2 / 10; } else { unit = chartable[c][curfont - 1]; unit = unit * cursize * 2 / 10; } unit = unit / 2 + unit % 2; return unit; } int getwidth(string & s) { int unit = 0; for(int i = 0; i < s.length(); i ++) unit += getwidth(s.at(i)); return unit; } void print() { cout << "Line " << linecnt << ": " << first; if(trailing >= 0) cout << " ... " << last; cout << " (" << trailing << " whitespace)" << endl; } void put(string token) { int tempwidth = getwidth(token); if(curw == 0) { curw = tempwidth; first = last = token; } else{ int tempwidth2 = tempwidth + getwidth(' '); if(curw + tempwidth2 > w) { linecnt ++; trailing = w - curw; print(); curw = tempwidth; first = last = token; } else{ curw += tempwidth2; last = token; } } spacesize = cursize; spacefont = curfont; } int main() { int num; cin >> num; int i; char tempc; int tempi; string line; //string token; getline(cin , line); for(i = 0; i < num; i ++) { getline(cin, line); istringstream is(line); vector<int> units; is.get(tempc); for(int j = 0; j < 6; j ++) { is >> tempi; units.push_back(tempi); } chartable.insert(make_pair(tempc, units)); } cin >> l >> w; pcnt = 0; while(l != 0) { getline(cin, line); spacefont = curfont = 1; spacesize = cursize = 10; linecnt = 0; pcnt ++; curw = 0; cout << "Paragraph " << pcnt << endl; for(i = 0; i < l; i ++) { string token; getline(cin , line); istringstream is(line); while(is >> token) { if(token.at(0) == '*' && token.size() >2 && (token.at(1) == 'f' || token.at(1) == 's')) { bool pass = true; if(token.at(1) == 'f') { if(token.size() > 3 || token.at(2) <= '0' || token.at(2) > '6') pass = false; } else if(token.at(1) == 's') { for(int k = 2; k < token.length(); k ++) { if(token.at(2) == '0' ||token.at(k) < '0' || token.at(k) > '9' || k > 3) { pass = false; break; } } } if(pass){ istringstream is(token); is >> tempc; is >> tempc; is >> tempi; if(tempc == 'f') curfont = tempi; else if(tempc == 's') cursize = tempi; continue; } } put(token); } } trailing = w - curw; linecnt ++; print(); cin >> l >> w; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator