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 |
Re:不知道是不是数据水,飘过In Reply To:不知道是不是数据水,飘过 Posted by:814264306 at 2019-07-16 20:08:42 > #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator