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 814264306 at 2019-07-16 20:08:42 on Problem 1129
#include<iostream>
#include<string>
#include<string.h>
using namespace std;

int main() {
	int n;
	string in[30];
	int color[30];
	while (cin >> n&&n) {
		//get
		for (int i = 0; i < n; i++) {
			color[i] = 1;
		}
		for (int i = 0; i < n; i++) {
			cin >> in[i];
		}
		//sort
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (in[i].length() < in[j].length()) {
					string t;t = in[i];in[i] = in[j];in[j] = t;
				}
			}
		}
		//color
		int ans = 1;
		for (int i = 0; i < n; i++) {
			int x = in[i][0] - 'A';
			for (int j = 2; j < in[i].length(); j++) {
				if (color[in[i][j] - 'A'] == color[x])
				{
					color[in[i][j] - 'A'] = color[x] + 1;
					if (ans < color[x] + 1)ans = color[x] + 1;
				}
			}
		}
		if(ans==1)
		cout << ans <<" channel needed." <<endl;
		else {
			cout << ans << " channels needed." << endl;
		}
	}
}

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