C++笔记:习题 3.7 (3.2.4)
/* C++ Primer 3.2.4 習題 3.7
* 題目: 編寫程序實現從標準輸入讀入兩個 string 對象,比較其是否相等,哪個較大,哪個較長。
*/
#include #include
using std::cin;
using std::cout;
using std::string;
using std::endl;
int main()
{
string s1, s2;
getline(cin, s1);
getline(cin, s2);
if (s1 == s2)
cout << "S1, S2 is the same." << endl;
else if (s1 > s2)
cout << "S1 is biger than S2." << endl;
else
cout << "S2 is biger than S1." << endl;
if (s1.length() == s2.length())
cout << "S1, S2 is the same length." << endl;
else if (s1.length() > s2.length())
cout << "S1 is longer than S2." << endl;
else
cout << "S2 is longer than S1." << endl;
return 0;
}
本文版权遵循 CC BY-NC-SA 4.0发布,转载需附带本文链接。
猜你喜欢
- 百度NOIP吧编程挑战赛 标程
- 【成绩】百度NOIP吧编程挑战赛成绩公布
- 百度NOIP吧编程挑战赛第二题 Special Judge 程序下载
- 百度NOIP吧编程挑战赛作弊嫌疑人名单
- 百度NOIP吧编程挑战赛测试数据下载
当前页阅读量为: