字符串-01~~~字符串-04
来源:互联网 发布:linux运维岗笔试题 编辑:程序博客网 时间:2024/05/18 02:53
int main()
{
using std::cin;
using std::cout;
char *p = new char[80];
char ch;
int mark=0;
cout << "Enter some words :\n";
cin.get(p, 80);
cout << "Your favorite character :\n";
cin >> ch;
int size = strlen(p);
for (int i = 0; i < size; i++)
{
if (p[i] == ch)
{
for (int j = i; j < size; j++)
cout << p[j];
mark++;
break;
}
}
if (!mark)
cout << "Not found .\n";
return 0;
}
字符串-02
#include<iostream>
#include<string>
int main()
{
using namespace std;
string s1, s2;
cout << "Enter s1:"; getline(cin, s1);
cout << "Enter s2:"; getline(cin, s2);
long ad = s1.find(s2);
while (ad != string::npos)
{
int m =s2.size();
s1.erase(ad, m);
ad = s1.find(s2);
}
cout << s1;
return 0;
}
字符串-03
#include<iostream>
#include<string>
using namespace std;
int main()
{
int a; int b;
cout << "Enter two num:"; cin >> a >> b;
string line[100];
cout << "Enter words:\n";
cin.get();
for (int i = 0; i < a; i++)
{
getline(cin, line[i]);
}
for (int i = b-1; i <a-1;i++)
{
string temp;
for (int j = i+1; j<a; j++)
{
if (line[i]>line[j])
{
temp = line[i];
line[i] = line[j];
line[j] = temp;
}
}
}
cout << "Show info :\n";
for (int i = 0; i < a; i++)
cout << line[i] << endl;
return 0;
}
字符串-04
#include<iostream>
using namespace std;
int main()
{
char line[30];
cout << "Enter some words:\n";
cin.get(line, 30);
int n = strlen(line);
for (int i = 0; i < n/2; i++)
{
char t;
t = line[i];
line[i] = line[n -1- i];
line[n - i-1] = t;
}
for (int i = 0; i < n; i++)
cout << line[i];
return 0;
}
- 字符串-01~~~字符串-04
- 字符串01~04
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 分支-16~~~分支-20
- Cleaning Robot
- 求一个3*3的整型矩阵对角线元素之和
- 简历制作-Word 2007插入相片
- shell脚本中的引用
- 字符串-01~~~字符串-04
- UVa - 1623 - Enter The Dragon
- 【Java进阶】单例模式详解
- 有关js和html的小细节
- 有一个已排好序的数组,要求输入一个数后,按原来排序的规律将它插入数组中
- Spring配置web.xml的<servlet>标签
- 学习MOOC——《国际贸易学》的总结
- 将一个数组中的值按逆序重新存放。
- Nginx rewrite URL examples with and without redirect address