[問題] 算次數問題
開發平台(Platform): (Ex: Win10, Linux, ...)Win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):算次數問題
餵入的資料(Input):
S V1;
S V2;
S V3;
V1 V2;
V1 V9;
V2 V3;
V3 V4;
V3 V6;
V2 V5;
V5 V7;
V6 V7;
V7 V9;
V7 T;
V4 V8;
V8 V10;
V8 T;
V9 T;
V10 T;
*[m
預期的正確結果(Expected Output):count = 12個
錯誤結果(Wrong Output):count = 13個
程式碼(Code):(請善用置底文網頁, 記得排版)
string input_name;
string cmp;
string start;
string s;
int count = 0;
input_file.open("input1.txt", ios::in); //開檔
if (!input_file)
{
cout << "開啟檔案開啟失敗";
system("pause");
}
while (!input_file.eof())
{
getline(input_file, start, ' '); //抓取空白格前的字元
getline(input_file, s);
if (count == 0)
{
cmp = start;
count++;
continue;
}
if (count != 0)
{
if (cmp.compare(start) == 0) //跟前一個比,相
同則不算一個點
continue;
else //不相同,則點數加一
{
cmp = start;
count++;
}
}
if (input_file.eof() == true) //最後一個點是終點,所以
無條件加一個點
count++;
}
補充說明(Supplement):S V1 V2 V3 V4 ...... T 都是點
由於我的算法是,每取道一個點,便檢查與上一個點是否相同,不相同則count不會
加一,但由於V2這個點,在第五行與第八行皆有出現,導致會多算一個點,不知道
要如何去做。P.S. 必須為動態的,因為不是每一次都為V2或第五行和第八行。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.135.9.165
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1480509730.A.0D2.html
→
11/30 21:46, , 1F
11/30 21:46, 1F
→
11/30 21:47, , 2F
11/30 21:47, 2F
推
12/01 16:45, , 3F
12/01 16:45, 3F
→
12/01 16:46, , 4F
12/01 16:46, 4F
→
12/01 16:46, , 5F
12/01 16:46, 5F
→
12/01 16:47, , 6F
12/01 16:47, 6F