[問題] 迴文
看板C_and_CPP (C/C++)作者handsome616 (豆花伯爵)時間13年前 (2011/08/20 16:23)推噓6(6推 0噓 9→)留言15則, 7人參與討論串2/5 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
code::block
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
爲什麼可以直接相加?
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <string>
using namespace std;
int main() {
string s1 ,s2;
while(cin >> s1 ) {
for(int i = 1 ; i <= s1.length() ; i++) {
s2 += s1[s1.length()-i] ;
}
if(s1==s2)
cout << "yes" << endl ;
else
cout << "no" << endl ;
s2 = "";
}
return 0;
}
補充說明(Supplement):
小弟在高中生解題系統上練習,本來是用getline的想法去寫
可是在google後找到這段程式碼,請教各位先進
爲什麼可以直接s2+=s1[s1.lenght()-1],好抽象
懇請各位解惑
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.122.14.27
推
08/20 16:43, , 1F
08/20 16:43, 1F
→
08/20 16:43, , 2F
08/20 16:43, 2F
→
08/20 16:43, , 3F
08/20 16:43, 3F
→
08/20 16:45, , 4F
08/20 16:45, 4F
→
08/20 16:47, , 5F
08/20 16:47, 5F
推
08/20 16:49, , 6F
08/20 16:49, 6F
→
08/20 16:54, , 7F
08/20 16:54, 7F
推
08/20 17:27, , 8F
08/20 17:27, 8F
推
08/20 17:39, , 9F
08/20 17:39, 9F
→
08/20 18:43, , 10F
08/20 18:43, 10F
→
08/20 18:44, , 11F
08/20 18:44, 11F
推
08/20 18:49, , 12F
08/20 18:49, 12F
→
08/20 20:46, , 13F
08/20 20:46, 13F
推
08/20 23:13, , 14F
08/20 23:13, 14F
→
08/21 00:38, , 15F
08/21 00:38, 15F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章