[ACM ] 10815

看板C_and_CPP (C/C++)作者時間16年前 (2010/02/28 23:43), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/1
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 ) ( 未必需要依照此格式,文章條理清楚即可 ) 題號:10815 http://0rz.tw/uypJA 遇到的問題: 不知為何一直Wrong answer = =" 有問題的code: (請善用置底文的標色功能) #include<iostream> #include<string> #include<map> #include<cctype> using namespace std; int main() { string x; string::iterator str; map<string,int> word; map<string,int>::iterator p; while(cin>>x,!cin.eof()) { for(str=x.begin();str!=x.end();) { if(!isalpha(*str)) str=x.erase(str); else { *str=tolower(*str); ++str; } } word[x]; } for(p=word.begin();p!=word.end();++p) cout<<p->first<<endl; } 補充說明: -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.241.200 ※ 編輯: flash5408 來自: 140.112.241.200 (03/01 00:06)

03/01 00:52, , 1F
下次測資請用檔案來做, 因為最後一行結尾是'\0'而不是
03/01 00:52, 1F

03/01 00:53, , 2F
'\n', 你用標準輸入可能很習慣最後按return, 而沒測試
03/01 00:53, 2F

03/01 00:54, , 3F
直接加EOF的結果, 更正, 最後一行結尾是EOF
03/01 00:54, 3F

03/01 00:58, , 4F
改成 : while( cin >> x, cin ) 應該就可以了
03/01 00:58, 4F
文章代碼(AID): #1BYeyZjj (C_and_CPP)
文章代碼(AID): #1BYeyZjj (C_and_CPP)