注册 登录
编程论坛 C++教室

关于c++字符串操作与动态空间管理的编程问题

qw2202e 发布于 2021-03-15 00:09, 1832 次点击
【问题描述】

输入若干个字符串(每个字符串的长度不超过30个字符,字符串总数不超过30),和一个英文字符。 要求:

     - 使用C++的string类型操作字符串,使用new和delete动态申请和撤销字符串空间

     - 删除每个字符串中的字符(区分大小写),得到新的字符串

     - 将新的字符串按照字典逆序排序后输出

【输入形式】

第一行输入英文字符

每一行输入一个字符串

最后一行单独输入特殊字符@做为结束标志

【输出形式】

删除ch的新字符串按字典逆序输出

每行输出一个字符串

【样例输入1】
7 回复
#2
qw2202e2021-03-15 08:11
哪位大佬能够指点一哈~~~~
#3
rjsp2021-03-15 08:36
看不懂,
描述估计是体育老师写的;
而“样例输入”不给,应该就是故意不想让人理解题目吧
#4
qw2202e2021-03-15 08:43
抱歉,"样例输入"在这儿

【样例输入1】
e
shangejiao
fudean
teongji
shangcai
@
【样例输出1】
tongji
shangjiao
shangcai
fudan
#5
qw2202e2021-03-15 08:43
【样例输入2】

E
Basicversion("DIEEE")
DIEEEdeterminesthetype
currentlytheprogramde
@
【样例输出2】

currentlytheprogramde
DIdeterminesthetype
Basicversion("DI")
#6
rjsp2021-03-15 09:30
使用new和delete动态申请和撤销字符串空间
不知道是什么意思

程序代码:
#include <iostream>
#include <vector>
#include <string>
#include <limits>
#include <algorithm>
using namespace std;

int main( void )
{
    char a;
    vector<string> s;

    cin >> a;
    cin.ignore( numeric_limits<streamsize>::max(), '\n' );
    for( string line; getline(cin,line) && line!="@"; )
    {
        line.erase( remove(line.begin(),line.end(),a), line.end() );
        s.push_back( line );
    }

    sort( s.begin(), s.end(), greater<string>() );
    copy( s.begin(), s.end(), std::ostream_iterator<string>(cout,"\n") );
}
#7
qw2202e2021-03-15 11:37
我也不知道
#8
qw2202e2021-03-15 12:01
回复 6楼 rjsp
感谢,我大致明白了!!
1