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

Re:OLE??

Posted by direfire at 2006-10-29 03:16:46 on Problem 1589
In Reply To:OLE?? Posted by:direfire at 2006-10-29 03:16:41
#include <iostream> 
#include <sstream> 
#include <string> 
#include <vector> 
#include <set> 
#include <map> 
#include <algorithm> 
#include <cstdio> 
#include <cstdlib> 
#include <cmath>
#include <math.h>
#include <string.h>
using namespace std; 

#define REP(i, n) for(int i = 0; i<(n); i++) 
#define abs(a) ((a) >= 0 ? (a) : -(a)) 
#define inf 999999999 
typedef vector<int> VI; 
typedef vector<string> VS; 
typedef long long i64; 
typedef unsigned long long u64;

int main()
{
	int n;
	VS v;
	while(1)
	{
		scanf("%d", &n);
		if (n == 0) {
			for (int i = 0; i < 60; i++) printf("-");
			printf("\n");	
		}
		v.clear();
		char buf[61];
		for (int i = 0; i < n; i++)
		{
			scanf("%s", &buf);	
			string t = buf;
			v.push_back(buf);
		}
		sort(v.begin(), v.end());
		int len = 0;
		for (int i = 0; i < n; i++)
			if (v[i].length() > len) len = v[i].length();
		int R = 1;
		for (R = 1; R <= n; R++)
		{
			int p = n/R;
			int q = n%R;
			int dd;
			if (q == 0) dd = (p-1)*(len+2) + len;
			else dd = p*(len+2)+len;
			if (dd<=60) break;	
		}
		int p = n/R;
		int q = n%R;
		for (int i = 0; i < 60; i++) printf("-"); printf("\n");
		for (int i = 0; i < R; i++)
		{
			int pnum;
			if (q!=0 && i < q) pnum = p+1;
			else pnum = p;
			for (int j = 0; j < pnum-1; j++)
			{
				printf("%s", v[j*R+i].c_str());
				for (int k = 0; k < len - v[j*R+i].length() + 2; k++) printf(" ");
			}
			printf("%s\n", v[(pnum-1)*R+i].c_str());	
		}
	}
	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