题目1090:路径打印
来源:互联网 发布:js的九九乘法表代码 编辑:程序博客网 时间:2024/06/01 20:53
弄了半天也没通过,搜索下才发现是题意模糊: 在输出子目录时,子目录的位置实际上没有变化,比如:a/b,在输出时,b前面应该有两个空格,而不是一个!!
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
char
* s[10];
char
path[50];
bool
cmp(
char
s1[],
char
s2[])
{
int
result =
strcmp
(s1, s2);
if
(result < 0)
return
true
;
else
return
false
;
}
void
Process(
int
i)
{
int
j, k;
int
len =
strlen
(s[i]);
//int high = 0;
for
(j = 0, k = 0; j<len;j++)
{
if
(s[i][j] ==
'\\'
)
{
s[i][j] =
'\0'
;
bool
newNode =
true
;
if
(i > 0)
{
char
* p =
strstr
(s[i-1], s[i]);
if
(p && (!s[i-1][j] || s[i-1][j]==
'\\'
))
{
newNode =
false
;
}
}
if
(newNode)
{
strcpy
(&path[k], &s[i][k]);
printf
(
"%s\n"
, path);
}
//path[high] = ' ';
//high++;
s[i][j] =
'\\'
;
while
(k < j+1){path[k]=
' '
; k++;}
k = j+1;
}
}
if
(k < j)
{
bool
newNode =
true
;
if
(i > 0)
{
char
* p =
strstr
(s[i-1], s[i]);
if
(p && (!s[i-1][j] || s[i-1][j]==
'\\'
))
{
newNode =
false
;
}
}
if
(newNode)
{
strcpy
(&path[k], &s[i][k]);
printf
(
"%s\n"
, path);
}
}
}
int
main()
{
int
N;
int
i;
while
(
scanf
(
"%d"
, &N) != EOF && N != 0)
{
for
(i = 0;i < N;i++)
{
s[i] = (
char
*)
malloc
(
sizeof
(
char
)* 50);
scanf
(
"%s"
, s[i]);
}
std::sort(s, s+N, cmp);
for
(i =0; i< N; i++)
{
Process(i);
}
printf
(
"\n"
);
for
(i = 0;i < N;i++)
{
free
(s[i]);
}
}
return
0;
}
/**************************************************************
Problem: 1090
User: phoenix198425
Language: C++
Result: Accepted
Time:0 ms
Memory:1020 kb
****************************************************************/
0 0
- 题目1090:路径打印
- 题目1090:路径打印
- 题目1090:路径打印
- 题目1090:路径打印
- 题目1090:路径打印。N叉树
- 九度 oj 题目1090:路径打印
- 【九度】题目1090:路径打印 && 【LeetCode】Simplify Path
- POJ 题目1505 Copying Books(DP,打印路径)
- UVA 题目10453 Make Palindrome(区间DP,打印路径)
- hdu 1026 Ignatius and the Princess I【bfs+路径打印】经典题目
- 九度OJ--1090--路径打印
- 九度1090-路径打印-多叉树
- 题目9:打印日期
- 题目1186:打印日期
- 题目1186:打印日期
- 题目1186:打印日期
- 题目1186:打印日期
- 题目1186:打印日期
- vrptw
- SNMP 报文格式
- Use aluminum poles, save trees!
- 集群资源调度系统简介与galaxy资源调度系统简介
- 12球找异常问题
- 题目1090:路径打印
- Mendeley插入引用和参考文献
- [java] 单例模式详解
- CString 使用详解
- div入门之边框(border),页面水平居中效果(margin)
- VC++界面编程总结
- 第一个UI界面
- vc++ string处理大全
- MFC指针的获取