作业10-1
本文发布于 1587 天前,最后更新于 1457 天前,其中的信息可能已经有所发展或是发生改变。
#include <bits/stdc++.h>
//1. 编写函数,取一个字符串的子串。
using namespace std;

string GetSubstring(string s,int a,int b)
{
		string ans(s,a,b);
		return ans;
}

int main()
{
		string s;
		int a,b;
		cout << "Input string"<<endl;//输入字符串
		cin >> s;
		cout << "Enter the substring subscript range to be obtained (the following table starts from 0)"<<endl;//输入要获取的子串下标范围(下表从0开始)
		cin >> a >> b;
		string ans = GetSubstring(s,a,b);
		cout << ans;
}
#include <bits/stdc++.h>
using namespace std;

//2. 编写函数,把一个字符串插入到另一个字符串中指定位置。

void AppSubstring(char *&s_1,int a,char *s_2)
{
		char *ans;

		int len = sizeof(s_1) + sizeof(s_2);
		int llen = 0;
		ans = new char[len];
		for(int i=0; i<=len; i++)
		{
				if(i==a+1)
						for(unsigned int ii=0; ii<strlen(s_2); ii++)
								ans[llen++] = s_2[ii];
				ans[llen++]=s_1[i];
		}
		delete s_1;
		s_1 = ans;
}

int main()
{
		char *s_1="abcfgh";
		char *s_2="de";
		int a = 2;
		AppSubstring(s_1,a,s_2);
		cout << s_1;
}
#include <bits/stdc++.h>
using namespace std;

//3. 编写函数,求一个字符串中不重复字符组成的字符串,如字符串“dasasew”的不重复字符串为“dasew”。(选做)

string NotRepeatingSubstring(string s)
{
		bool PdAscii[256];
		memset(PdAscii,0,sizeof(PdAscii));
		char ans[256];
		int n=0;
		for(int i=0; i<=s.length(); i++)
		{
				if(!PdAscii[s[i]])
				{
						PdAscii[s[i]]=1;
						ans[n++]=s[i];
				}
		}
		return ans;
}

int main()
{
		string s;
		cin >> s;
		string ans = NotRepeatingSubstring(s);
		cout << ans;
}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇