游客 Signup | Login
中文 | En

3420 - 第七题 字符串拆分

将一个字符串按照指定的位置,分割为2个子串,并输出(从1开始计数,空格也算一个位置)。

Input

输入一个字符串(长度不超过100);并输入制定位置。

Output

第一行输出拆分后的第一个字符串;第二行输出拆分后的第二个字符串;

Examples

Input

HELLO WORLD
4

Output

HELL
O WORLD

Solution C

int main(int argc, const char * argv[]) {
    char data[100];
    char str1[100];
    char str2[100];
    int length = 0;
    int position = 4;
   gets(data);
  
    scanf("%d",&position);
    memcpy(str1,data,sizeof(char)*position);
    strcpy(str2, &data[position]);
    printf("%s\n",str1);
    printf("%s\n",str2);
}

Solution C++

#include<bits/stdc++.h>
using namespace std;
string a;
int t;
int main()
{
	getline(cin,a);
	cin>>t;
	for(int i=0;i<t;i++)
		cout<<a[i];
	cout<<endl;
	for(int i=t;i<a.size();i++)
		cout<<a[i];
   return 0;
}

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题