| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 413 人关注过本帖
标题:一小段程序,无法看到输出结果。求教。。谢谢。。
只看楼主 加入收藏
dyc9422
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-5-19
收藏
 问题点数:0 回复次数:0 
一小段程序,无法看到输出结果。求教。。谢谢。。

#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。试用这个排除集编写程序,删除输入单词的复数后缀,而如果输入的是排除集中的单词,则保持该单词不变。。求教...谢谢。。。

搜索更多相关主题的帖子: 结果 输出 
2007-05-27 19:54
快速回复:一小段程序,无法看到输出结果。求教。。谢谢。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011142 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved