当前位置:网站首页>Intercept string (function)

Intercept string (function)

2022-06-11 15:19:00 Psychic hacker

Title Description

Programming , Its effect is , From string 1 ( The length exceeds 30) Of the index Copy all characters starting with characters , Generate a new string 2.

Input

Number of groups of test data n

The first set of data

The second set of data

........

Output

The substring will be output after successful generation , Failed to generate , Output "IndexError"

sample input

3
Zhenshen University
9
www.szu.edu.cn
12
apple
8

sample output

University
cn
IndexError

Code

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t,i;
	string a;
	cin>>t;
	while(t--)
	{
		getchar();
		getline(cin,a);
		int index;
		cin>>index;
		if(index>=a.size())
		cout<<"IndexError"<<endl;
		else
		{
			for(i=index;a[i];i++)
			cout<<a[i];
			cout<<endl;
		}
	}
}

原网站

版权声明
本文为[Psychic hacker]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203012008017981.html