[問題] ACM 494
看板C_and_CPP (C/C++)作者listplayers (listplayers)時間15年前 (2011/07/07 22:26)推噓2(2推 0噓 5→)留言7則, 4人參與討論串1/1
想問一下這題它所給的測試資料
除了網頁上的
Meep Meep!
I tot I taw a putty tat.
I did! I did! I did taw a putty tat.
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...
之外,有可能出現像這種
!asdf這種情況嗎?
因為我的程式是抓每行裡面的每個字
然後判斷第一個字元是不是alpha的這種偷吃步的方法XD
所以想問一下有沒有什麼狀況是無法判斷的
以下是我的程式碼,謝謝
#include <iostream>
#include <sstream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string line, word;
int count = 0;
while (getline(cin,line)) {
istringstream stream(line);
while (stream >> word) {
if (isalpha(word[0]))
count++;
}
cout << count << "\n";
count = 0;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.216.171.14
→
07/07 22:30, , 1F
07/07 22:30, 1F
→
07/07 23:15, , 2F
07/07 23:15, 2F
→
07/08 00:10, , 3F
07/08 00:10, 3F
推
07/08 00:11, , 4F
07/08 00:11, 4F
→
07/08 00:12, , 5F
07/08 00:12, 5F
→
07/08 12:13, , 6F
07/08 12:13, 6F
推
07/08 12:14, , 7F
07/08 12:14, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章