1452 - C语言-子串

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。

题目输入

数字n 一行字符串 数字m

题目输出

从m开始的子串

输入/输出样例

输入格式

6
abcdef
3

输出格式

cdef

C语言解答

#include<stdio.h>
int main()
{
    char c[100];
    int a,b;
    scanf("%d",&a);
    char x=getchar();
    gets(c);
    scanf("%d",&b);
    for(int i=b-1;c[i]!='\0';i++)
        printf("%c",c[i]);
}

C++解答

#include<cstdio>
int main()
{
	int n,t;
	char *r;
	while(scanf("%d",&n)!=-1)
	{
		r=new char[n+2];
		while(gets(r)&&r[0]=='\0');
		scanf("%d",&t);
		if(t<n)
			printf("%s",r+t-1);
		printf("\n");
		delete r;
	}
	return 0;
}

Java解答

import java.util.*;
public class Main 
{
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);
		String s;
		int n,m;
		while(cin.hasNext())
		{
			n=cin.nextInt();
			cin.nextLine();
			s=cin.nextLine();
			m=cin.nextInt();
			System.out.println(s.substring(m-1));
		}
		cin.close();
	}
}