Time Limit: 1 Sec Memory Limit: 2 MB
Submit: 1910 Solved: 360
[Submit][Status]
Description
对给定的一个字符串,截取其中一部分输出。
Input
输入为两行,第一行为一个字符串s,长度至少为1且不超过20个字符;第二行为两个整数p、q,满足p<=q。
Output
输出s中下标从p到q的那部分,且p或q在s下标范围外的部分不会产生输出。若s[p]到s[q]不产生任何输出,则仅输出“[]”。
Sample Input
communication -10 10
Sample Output
[communicati]
HINT
Append Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main()
{
char
s[25];
int
p,q,l,i;
gets
(s);
scanf
(
"%d %d"
,&p,&q);
l=
strlen
(s);
if
(q<0||p>l-1)
printf
(
"[]"
);
else
if
(p<0&&q<l)
{
printf
(
"["
);
for
(i=0;i<=q;i++)
{
printf
(
"%c"
,s[i]);
}
printf
(
"]"
);
}
else
if
(q>l-1&&p>=0)
{
printf
(
"["
);
for
(i=p;i<l;i++)
{
printf
(
"%c"
,s[i]);
}
printf
(
"]"
);
}
else
{
printf
(
"["
);
for
(i=p;i<=q;i++)
{
printf
(
"%c"
,s[i]);
}
printf
(
"]"
);
}
return
0;
}