hiho 1383 The Book List
4784 단어 데이터 구조
시간 제한:
1000ms
단일 시간:
1000ms
메모리 제한:
256MB
묘사 하 다.
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:
ART
HISTORY
CHINESE HISTORY
THREE KINDOM
RESEARCHES ON CAOCAO
RESEARCHES ON LIUBEI
CHINESE MORDEN HISTORY
JAPANESE HISTORY
JAPANESE ACIENT HISTORY
MATH
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.
샘플 입력
B/A
B/A
B/B
0
A1/B1/B32/B7
A1/B/B2/B4/C5
A1/B1/B2/B6/C5
A1/B1/B2/B5
A1/B1/B2/B1
A1/B3/B2
A3/B1
A0/A1
0
샘플 출력
Case 1:
B
A
B
Case 2:
A0
A1
A1
B
B2
B4
C5
B1
B2
B6
C5
B1
B5
B32
B7
B3
B2
A3
B1
: windows , , , ,
: +map , , , set
#include
using namespace std;
#define maxn 3010
struct node
{
map mp;
set s;
}p[maxn];
void dfs(int u,int deep)
{
for(auto &i:p[u].mp)
{
int N=4*(deep-1);
for(int j=1;j<=N;j++) putchar(' ');
puts(i.first.c_str());
dfs(i.second,deep+1);
}
for(auto &i:p[u].s)
{
int N=4*(deep-1);
for(int j=1;j<=N;j++) putchar(' ');
puts(i.c_str());
}
}
int main()
{
char ch[110],c[110];
int num=0,cnt;
int ca=0;
while(gets(ch))
{
int n=strlen(ch);
if(n==1&&ch[0]=='0')
{
printf("Case %d:
",++ca);
dfs(0,1);
num=0;
for(int i=0;i
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
정수 반전Udemy 에서 공부 한 것을 중얼거린다 Chapter3【Integer Reversal】 (예) 문자열로 숫자를 반전 (toString, split, reverse, join) 인수의 수치 (n)가 0보다 위 또는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.