描述

The history of Peking University Library is as long as the history of Peking University. It was build in 1898. At the end of year 2015, it had about 11,000 thousand volumes of books, among which 8,000 thousand volumes were paper books and the others were digital ones. Chairman Mao Zedong worked in Peking University Library for a few months as an assistant during 1918 to 1919. He earned 8 Dayang per month there, while the salary of top professors in Peking University is about 280 Dayang per month.

Now Han Meimei just takes the position which Chairman Mao used to be in Peking University Library. Her first job is to rearrange a list of books. Every entry in the list is in the format shown below:

CATEGORY 1/CATEGORY 2/..../CATEGORY n/BOOKNAME

It means that the book BOOKNAME belongs to CATEGORY n, and CATEGORY n belongs to CATEGORY n-1, and CATEGORY n-1 belongs to CATEGORY n-2...... Each book belongs to some categories. Let's call CATEGORY1  "first class category", and CATEGORY 2 "second class category", ...ect. This is an example:

MATH/GRAPH THEORY
ART/HISTORY/JAPANESE HISTORY/JAPANESE ACIENT HISTORY
ART/HISTORY/CHINESE HISTORY/THREE KINDOM/RESEARCHES ON LIUBEI
ART/HISTORY/CHINESE HISTORY/CHINESE MORDEN HISTORY
ART/HISTORY/CHINESE HISTORY/THREE KINDOM/RESEARCHES ON CAOCAO

Han Meimei needs to make a new list on which the relationship between books and the categories is shown by indents. The rules are:

1) The n-th class category has an indent of  4×(n-1) spaces before it.
2) The book directly belongs to the n-th class category has an indent of  4×n spaces before it.
3) The categories and books which directly belong to a category X should be list below X in dictionary order. But all categories go before all books.
4) All first class categories are also list by dictionary order.

For example, the book list above should be changed into the new list shown below:

  1. ART
  2. HISTORY
  3. CHINESE HISTORY
  4. THREE KINDOM
  5. RESEARCHES ON CAOCAO
  6. RESEARCHES ON LIUBEI
  7. CHINESE MORDEN HISTORY
  8. JAPANESE HISTORY
  9. JAPANESE ACIENT HISTORY
  10. MATH
  11. GRAPH THEORY

Please help Han Meimei to write a program to deal with her job.

输入

There are no more than 10 test cases.
Each case is a list of no more than 30 books, ending by a line of "0". 
The description of a book contains only uppercase letters, digits, '/' and spaces, and it's no more than 100 characters.
Please note that, a same book may be listed more than once in the original list, but in the new list, each book only can be listed once. If two books have the same name but belong to different categories, they are different books.

输出

For each test case, print "Case n:" first(n starts from 1), then print the new list as required.

样例输入

  1. B/A
  2. B/A
  3. B/B
  4. 0
  5. A1/B1/B32/B7
  6. A1/B/B2/B4/C5
  7. A1/B1/B2/B6/C5
  8. A1/B1/B2/B5
  9. A1/B1/B2/B1
  10. A1/B3/B2
  11. A3/B1
  12. A0/A1
  13. 0

样例输出

  1. Case 1:
  2. B
  3. A
  4. B
  5. Case 2:
  6. A0
  7. A1
  8. A1
  9. B
  10. B2
  11. B4
  12. C5
  13. B1
  14. B2
  15. B6
  16. C5
  17. B1
  18. B5
  19. B32
  20. B7
  21. B3
  22. B2
  23. A3
  24. B1
    只有代码,题解。。。
  1. #include <math.h>
  2. #include <time.h>
  3. #include <sstream>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <set>
  8. #include <map>
  9. #include <string>
  10. #include <stack>
  11. #include <queue>
  12. #include <vector>
  13. #include <bitset>
  14. #include <iostream>
  15. #include <algorithm>
  16. #define pb push_back
  17. #define fi first
  18. #define se second
  19. #define icc(x) (1<<(x))
  20. #define lcc(x) (1ll<<(x))
  21. #define lowbit(x) (x&-x)
  22. #define debug(x) cout<<#x<<"="<<x<<endl
  23. #define rep(i,s,t) for(int i=s;i<t;++i)
  24. #define per(i,s,t) for(int i=t-1;i>=s;--i)
  25. #define mset(g, x) memset(g, x, sizeof(g))
  26. using namespace std;
  27.  
  28. typedef long long ll;
  29. typedef unsigned long long ull;
  30. typedef unsigned int ui;
  31. typedef double db;
  32. typedef pair<int,int> pii;
  33. typedef pair<ll,ll> pll;
  34. typedef vector<int> veci;
  35. const int mod=(int)1e9+7,inf=0x3fffffff,rx[]={-1,0,1,0},ry[]={0,1,0,-1};
  36. const ll INF=1ll<<60;
  37. const db pi=acos(-1),eps=1e-8;
  38.  
  39. template<class T> void rd(T &res){
  40. res = 0; int ch,sign=0;
  41. while( (ch=getchar())!='-' && !(ch>='0'&&ch<='9'));
  42. if(ch == '-') sign = 1; else res = ch-'0';
  43. while((ch=getchar())>='0'&&ch<='9') res = (res<<3)+(res<<1)+ch-'0';
  44. res = sign?-res:res;
  45. }
  46. template<class T>void rec_pt(T x){
  47. if(!x)return;
  48. rec_pt(x/10);
  49. putchar(x%10^48);
  50. }
  51. template<class T>void pt(T x){
  52. if(x<0) putchar('-'),x=-x;
  53. if(!x)putchar('0');
  54. else rec_pt(x);
  55. }
  56. template<class T>inline void ptn(T x){ pt(x),putchar('\n'); }
  57. template<class T>inline void Max(T &a,T b){ if(b>a)a=b; }
  58. template<class T>inline void Min(T &a,T b){ if(b<a)a=b; }
  59. template<class T>inline T mgcd(T b,T d){ return b?mgcd(d%b,b):d; }//gcd模板,传入的参数必须是用一类型
  60. //-------------------------------主代码--------------------------------------//
  61.  
  62. char str[33][1100];
  63. string ss[33];;
  64.  
  65. int main()
  66. {
  67. int tt=1;
  68. int cnt=0;
  69. while(gets(str[cnt])){
  70. if(str[cnt][0]=='0' &&strlen(str[cnt])==1){
  71. printf("Case %d:\n",tt++);
  72. rep(i, 0, cnt){
  73. ss[i]="";
  74. int prej = 0;
  75. rep(j, 0, strlen(str[i])){
  76. if(str[i][j]==' ') str[i][j]='&';
  77.  
  78. if(str[i][j]=='/'){
  79. string tmp= "%";
  80.  
  81. rep(k, prej, j){
  82. tmp += str[i][k];
  83. }
  84. ss[i] += tmp;
  85. ss[i] += "!";
  86. prej = j+1;
  87. }
  88. }
  89. rep(j, prej, strlen(str[i])){
  90. ss[i] += str[i][j];
  91. }
  92. }
  93. sort(ss,ss+cnt);
  94. rep(i, 0, cnt){
  95. if(i==0){
  96. int n = 0;
  97. rep(j, 0, ss[i].length()){
  98. if(ss[i][j] == '%')continue;
  99. if(ss[i][j] == '&'){ printf(" "); continue;}
  100. if(ss[i][j] == '!'){
  101. n++;
  102. puts("");
  103. rep(k, 0, 4*n){
  104. putchar(' ');
  105. }
  106. }else printf("%c",ss[i][j]);
  107. }
  108. //puts("");
  109. //if(cnt!=1) puts("");
  110. continue;
  111. }
  112. if(ss[i]==ss[i-1]) continue;
  113. int pp=0;
  114. int n=0;
  115. rep(j, 0, ss[i-1].length()){
  116.  
  117. if(ss[i][j] != ss[i-1][j]){
  118. break;
  119. }
  120. if(ss[i][j] == '!'){
  121. n++;
  122. pp = j+1;
  123. }
  124. }
  125. //while(pp>0 && ss[i][pp]!='!') pp--;
  126. puts("");
  127. rep(j, 0, 4*n) putchar(' ');
  128.  
  129. rep(j, pp, ss[i].length()){
  130. if(ss[i][j] == '%')continue;
  131. if(ss[i][j] == '&'){ printf(" "); continue;}
  132. if(ss[i][j] == '!'){
  133. n++;
  134. puts("");
  135. rep(k, 0, 4*n){
  136. putchar(' ');
  137. }
  138. }else printf("%c",ss[i][j]);
  139. }
  140.  
  141. }
  142. cnt = 0;
  143. printf("\n");
  144. //tt++;
  145. }else{
  146. cnt++;
  147. }
  148. }
  149. return 0;
  150. }

  

ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List的更多相关文章

  1. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job

    描述 Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute ...

  2. hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...

  3. hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...

  4. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  5. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  6. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6

    #1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...

  7. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

  8. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  9. 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute

    题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...

随机推荐

  1. .NET: C#: 获取当前路径

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  2. DataBase: LeetCode

    Combine Two Tables # Write your MySQL query statement below Select p.FirstName, p.LastName, a.City, ...

  3. CCS3属性之text-overflow:ellipsis;的用法和注意之处

    语法: text-overflow:clip | ellipsis 默认值:clip 适用于:所有元素 clip: 当对象内文本溢出时不显示省略标记(...),而是将溢出的部分裁切掉. ellipsi ...

  4. PAT乙级 1002. 写出这个数 (20)

    1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...

  5. zw版【转发·台湾nvp系列Delphi例程】HALCON HWindowX 02

    zw版[转发·台湾nvp系列Delphi例程]HALCON HWindowX 02 procedure TForm1.Button1Click(Sender: TObject);var img : H ...

  6. zw版【转发·台湾nvp系列例程】HALCON EquHistoImage(Delphi)

    zw版[转发·台湾nvp系列例程]HALCON EquHistoImage(Delphi) zw版[转发·台湾nvp系列例程]HALCON EquHistoImage(Delphi) (Delphi ...

  7. 在线白板,基于socket.io的多人在线协作工具

    首发:个人博客,更新&纠错&回复 是昨天这篇博文留的尾巴,socket.io库的使用练习,成品地址在这里. 代码已经上传到github,传送门.可以开俩浏览器看效果. 现实意义是俩人在 ...

  8. struts2 笔记04 杂记

    流程: 1. StrutsPrepareAndExcuteFilter:StrutsPrepareAndExcuteFilter作为前端控制器,是整个Struts2的调度中心. 2. ActionMa ...

  9. 关于web开发前端h5框架的选择

    关于web开发前端h5框架的选择 看了很多移动版框架都是基于app混合式开发的,不是单独h5网站的基于h5开发的web框架从组件丰富度,兼容性,相关教程来说bootstrap还是最好的react和vu ...

  10. arm驱动linux异步通知与异步IO【转】

    转自:http://blog.csdn.net/chinazhangzhong123/article/details/51638793 <[ arm驱动] linux异步通知与 异步IO> ...