看板 C_and_CPP 關於我們 聯絡資訊
#include <iostream> #include <string> #include <algorithm> #include <fstream> using namespace std; int main() { ifstream Input("input.txt"); ofstream Output("output.txt"); if(!Input) { exit(1); } string temp; while(getline(Input, temp)) { for(string::size_type ix = 0; ix < temp.size(); ix++) if(temp[ix] < 0) swap(temp[ix], temp[ix++]); reverse(temp.begin(), temp.end()); Output << temp << '\n'; temp.clear(); } Input.close(); Output.close(); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.116.165.235 ※ 編輯: joefaq 來自: 59.116.165.235 (03/22 12:17)
grantchiue:不過我是試著使用陣列去互相傳入,目前不太考慮用 03/22 12:17
grantchiue:reverse來寫,還是說不用reverse會寫不出來 囧? 03/22 12:17
※ 編輯: joefaq 來自: 59.116.165.235 (03/22 12:21)
grantchiue:我也先試試看這方法,感謝(跪 03/22 12:40
grantchiue:這方法完全可行 囧!我繼續研究(磕頭 03/22 12:43
grantchiue:基本上都看懂了,不過我有一個地方不太懂,就是判斷是 03/22 18:58
grantchiue:否為中文字的那個swap,為什麼是寫if(temp[ix] < 0)呢 03/22 18:58
Kawasumi:你用bitwise去想 中文字的特徵就是第一個byte的第一bit是 03/22 20:07
Kawasumi:零,這對應到signed char型態的話,就是負數了 03/22 20:07
Kawasumi:更正 第一個byte的第一個bit是1 03/22 20:08
grantchiue:感謝O3Q 我懂了! 03/22 21:52
LoCKeR941010:想請問一下 我這個方法在DevC可行 可是在VC就沒辦法 03/23 18:06
LoCKeR941010:在VC 中文字串會變亂碼 這是為什麼? 03/23 18:06