找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 198|回复: 0

一小段程序,无法看到输出结果。求教。。谢谢。。

[复制链接]
发表于 2009-11-6 01:35:13 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
using namespace std;
int main()
{
set<string> excluded;
string undel_word;
cout<<"Enter undelete words:"<<endl;
while (cin>>undel_word)
{ pair<set<string>::iterator,bool> ret=excluded.insert(undel_word);
if(!ret.second)
cout<<"reapeated ,Enter another words:"<<endl;
}
for (set<string>::iterator it=excluded.begin();it!=excluded.end();++it)
cout<<*it<<endl;
// 为何上面一段代码不行呢?也是读入单词,输出也可以看到确实已存入map<string>excluded
而后面 if(!excluded.count(word))这段就是读不出来。请教。。谢谢了。。



// excluded.insert(undelete_word); 附:用这段代码编译运行后可以看到输出结果
// excluded.insert("success");
// excluded.insert("class");


string word;
cout<<"Enter a word(Ctrl+Z to end)"<<endl;
while(cin>>word)
{ if(!excluded.count(word))
word.resize(word.size()-1);
cout<<"non-plural version:"<<word<<endl;
cout<<"Enter a word(Ctrl+Z to end)"<<endl;
}

/* { string::size_type length=word.size(); 附:此段为自己写的比较笨拙的一段。。
cout<<"non-plural version: ";
for(string::size_type ix=0;ix!=length;++ix)
cout<<word[ix];
cout<<endl;
}
else cout<<word<<endl;
}
*/
getchar();
return 0;

}

程序大意:通过删除单词尾部的‘s’生成该单词的非复数版本,同时,建立一个map<string>excluded的排除集,用于识别以‘s’结尾,但这个结尾的‘s’又不能删除的单词。例如:放在该排除集中的单词可能有success和class。试用这个排除集编写程序,删除输入单词的复数后缀,而如果输入的是排除集中的单词,则保持该单词不变。。求教...谢谢。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 17:27 , Processed in 0.112818 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表