Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一道水题。

Posted by KatrineYang at 2017-01-20 13:03:47 on Problem 1589
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int N;
	while(cin >> N){
		vector<string> vs;
		int maxLen = 0;
		for(int i = 0; i < N; i++){
			string tmp;
			cin >> tmp;
			int len = tmp.length();
			if(len > maxLen) maxLen = len;
			vs.push_back(tmp);
		}
		int R, C;
		C = 62/(maxLen+2);
		R = (N-1)/C+1;
		sort(vs.begin(), vs.end());
		for(int i = 0; i < 60; i++) cout << "-"; cout << endl;
		for(int r = 0; r < R; r++){
			int n = r;
			while(1){
				cout << vs[n];
				int tLen = vs[n].length();
				for(int i = 0; i < maxLen-tLen; i++) cout << " ";
				n += R;
				if(n >= N){
					cout << endl;
					break;
				}
				else{
					cout << "  ";
				}
			}
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator