网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月22日漏签0天
c++吧 关注:629,918贴子:2,113,821
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 1 2 下一页 尾页
  • 21回复贴,共2页
  • ,跳到 页  
<<返回c++吧
>0< 加载中...

难题,不服的来

  • 收藏

  • 回复
  • 219.243.95.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
查找并删除某个同学的姓名。例如:输入的同学姓名分别为:Li Fang ,  Wang Li  , Xiao hanxiong , Feng Lei ,  Fu Xiaoxiao  ,要查找并删除的同学的姓名为:Feng Lei. 则删除后,同学姓名包含有:Li Fang  , Wang Li ,  Xiao hanxiong  , Fu Xiaoxiao 。假设全班同学不超过50名,每个人姓名长度不超过30个字符。


  • 219.243.95.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
en


2025-08-22 19:39:18
广告
不感兴趣
开通SVIP免广告
  • 218.75.240.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这都能叫难题,一点技术含量都都没有.
而且完全没有意义,如果有重名的怎么办?


  • 219.243.95.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
初学者,用函数创新做


  • 60.25.37.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我最看不起打劫的,一点技术含量都没有


  • 8pm
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#if !defined(STUDENT_CLASS)
#define STUDENT_CLASS 1.0.1

#include <algorithm>
#include <iostream>
#include <string>
#include <list>


class school_class {
    typedef std::list<std::string>::const_iterator student;
public:

    bool empty() const throw();
    void add_student(const std::string &newbie) throw();
    void expel_student(const std::string &bad_boy) throw();
    bool find_student(const std::string &some_one) const throw();
    void list_students() const throw();

private:
    std::list<std::string> student_list;
};

inline
bool school_class::empty() const throw()
{ return student_list.empty(); }

inline
void school_class::add_student(const std::string &newbie) throw()
{ student_list.push_back(newbie); }

inline
void school_class::expel_student(const std::string &bad_boy) throw()
{ student_list.remove(bad_boy); }

inline
bool school_class::find_student(const std::string &some_one) const throw()
{ return std::count(student_list.begin(), student_list.end(), some_one) != 0; }

inline
void school_class::list_students() const throw()
{
    for (student some_one = student_list.begin();
        some_one != student_list.end();
        ++some_one)
        std::cout<<*some_one<<std::endl;
}

#endif // STUDENT_CLASS 1.0.1

using std::cout;
using std::endl;
using std::cin;
using std::getline;
using std::string;

int main()
{
    school_class my_class;
    string name;
    while (cout<<"enter student : ", getline(cin, name) && !name.empty())
        my_class.add_student(name);
    while (!my_class.empty()) {
        cout<<endl
            <<string(5, '-')<<"[students in the class]"<<string(5, '-')<<endl;
        my_class.list_students();
        cout<<string(8 , '-')<<"[end of the list]"<<string(8, '-')<<endl;
        cout<<"enter the name of the student to be kicked out: "<<endl;
        getline(cin, name);
        if (name.empty()) break;
        if (my_class.find_student(name)) {
            my_class.expel_student(name);
            cout<<name<<" is out."<<endl;
        } else
            cout<<endl<<"hey man, no such student!"<<endl;
    }
    cout<<endl<<"bye."<<endl;
    return 0;
}


  • elva6401
  • throw
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
激将法还很有用.
把8pm都激来了,写程序.呵呵


  • 222.240.143.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include <algorithm>
这是什么头文件


2025-08-22 19:33:18
广告
不感兴趣
开通SVIP免广告
  • 219.134.80.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
谁说打劫的没技术含量,张君连续打劫9年后才被抓住,要不你试试?哈哈!


  • 8pm
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
改进一点,这样更好拿分。有 STL、函数重载、虚函数、异常、动态类型,题目太简单了,不好搞更多的东东,将就将就吧。
#if !defined(STUDENT_CLASS)
#define STUDENT_CLASS 1.0.2

#include <algorithm>
#include <ostream>
#include <stdexcept>
#include <string>
#include <list>

namespace sc {

class school_class {
    typedef std::list<std::string>::const_iterator student;
public:

    virtual ~school_class() {}
    bool empty() const throw();
    void add_student(const std::string &newbie) throw();
    void expel_student(const std::string &bad_boy)
        throw(std::invalid_argument);
    bool find_student(const std::string &some_one) const throw();

    operator bool() const throw();
    friend std::ostream& 
        operator <<(std::ostream &out, const school_class &c) throw();

protected:
    virtual void list_students(std::ostream &out) const throw();

private:
    std::list<std::string> student_list;
};

inline
bool school_class::empty() const throw()
{ return student_list.empty(); }

inline
void school_class::add_student(const std::string &newbie) throw()
{ student_list.push_back(newbie); }

inline
void school_class::expel_student(const std::string &bad_boy)
    throw(std::invalid_argument)
{
    if (find_student(bad_boy)) student_list.remove(bad_boy);
    else throw std::invalid_argument("no such student [" + bad_boy + "]");
}

inline
bool school_class::find_student(const std::string &some_one) const throw()
{ return std::count(student_list.begin(), student_list.end(), some_one) != 0; }

inline
void school_class::list_students(std::ostream &out) const throw()
{
    out<<std::endl<<std::string(5, '-')<<"[students in the class]"
        <<std::string(5, '-')<<std::endl;
    for (student some_one = student_list.begin();
        some_one != student_list.end();
        ++some_one)
        out<<*some_one<<std::endl;
    out<<std::string(8 , '-')<<"[end of the list]"



  • 8pm
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
        <<std::string(8, '-')<<std::endl;
}

inline
school_class::operator bool() const throw()
{ return !empty(); }

inline
std::ostream&
operator <<(std::ostream &out, const school_class &c) throw()
{ c.list_students(out); return out; }

} // namespace sc

#endif // STUDENT_CLASS 1.0.2

#include <iostream>
using std::cout;        using std::cerr;
using std::endl;        using std::cin;
using std::getline;     using std::string;
using std::exception;   using std::invalid_argument;
using namespace sc;

int main()
{
    school_class my_class;
    string name;
    while (cout<<"enter student : ", getline(cin, name) && !name.empty())
        my_class.add_student(name);
    while (my_class) {
        cout<<my_class
            <<"enter the name of the student to be kicked out: "<<endl;
        getline(cin, name);
        if (name.empty()) break;
        try {
            my_class.expel_student(name);
            cout<<name<<" is out."<<endl;
        }
        catch (exception &e) {
            if (typeid(e) == typeid(invalid_argument))
                cerr<<"hey man, be careful!"<<endl;
            cerr<<"exception ["<<typeid(e).name()<<"]: "<<e.what()<<endl;
        }
    }
    cout<<endl<<"bye."<<endl;
    return 0;
}


  • elva6401
  • throw
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include <algorithm>
里面包含基本的算法.


  • 219.243.95.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
AKUMA帮我看一眼求一个6位数那题,来个经典点的成不?多谢


  • 219.243.95.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
高,谢了


2025-08-22 19:27:18
广告
不感兴趣
开通SVIP免广告
  • 218.69.112.*
快试试吧,
可以对自己使用挽尊卡咯~
◆
◆
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
天哪,有没有简单一点的程序,我刚刚学C语言,看不懂啊.
大哥,可不可以给个简单的程序.


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1 2 下一页 尾页
  • 21回复贴,共2页
  • ,跳到 页  
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示