编写程序,输入若干个字符串。要求:(1)按字符串长度的大小升序输出各个字符串。(2)按字符串中字符的ASCLL码值大小升序输出各个字符串。为什么我输不出结果来???我该如何改呢?#include
#include
#include
#include
using namespace std;
//比较函数,用于排序
bool compare(string a, string b) {
//长度不一样的时候采用长度来排序
if (a.length() != b.length()) {
return a.length() < b.length();
}
//长度一样的时候采用ASCLL值排序
return a < b;
}
int main()
{vectorlist;
string inputString;
while (cin >> inputString) {
//结束标志,测试方便,可以注释掉
if (inputString == "0") {
break;
}
//加入到vector
list.push_back(inputString);
}
//排序,系统方法
sort(list.begin(), list.end(), compare);
//依次输出
for (unsigned int i = 0; i<list.size(); i++) {
cout << list[i] << endl;
}
return 0;
}
C++小程序,调试。。。。。。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- threenewbee 2016-02-20 22:50关注
aaa bbb ccc ddd aa bb cc dd hello yellow hungry 0 aa bb cc dd aaa bbb ccc ddd hello hungry yellow Press any key to continue
没发现问题。只是(2)你没有做。
解决 无用评论 打赏 举报
悬赏问题
- ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
- ¥15 让node服务器有自动加载文件的功能
- ¥15 jmeter脚本回放有的是对的有的是错的
- ¥15 r语言蛋白组学相关问题