Re: [ACM] 新手問一下

看板C_and_CPP作者 (/* I'm not worth */)時間15年前 (2010/08/05 23:52), 編輯推噓1(1013)
留言14則, 4人參與, 最新討論串2/2 (看更多)
※ 引述《vic1225 (/* I'm not worth */)》之銘言: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36 ACM題目 像這題 就是要input然後輸出output 我想問的是她input的是要我寫成讀檔嗎? 還是cin給他輸入呢? (要cout提示他要輸入嗎?) 然後output是直接cout嗎 還是要輸出到檔案? 第一次玩這種題目不清楚 希望大神們指教一下 謝謝!! 這是題目id 100 我的code如下 #include <iostream> using namespace std; int count_number_of_cycle(int n, int t); int main(){ cout << "輸入 x y" << endl; int x, y; cin >> x >> y; int max = 0; int temp = 0; //find max cycle between x, y for(int i = x; i <= y; i++){ if(max < (temp = count_number_of_cycle(i, 0))) max = temp; } cout << x << " " << y << " " << max << endl; system("pause"); return 0; } int count_number_of_cycle(int n, int count){ if(n == 1) return count + 1; else if(n % 2 == 0) return count_number_of_cycle(n / 2, count + 1); else return count_number_of_cycle(3 * n + 1, count + 1); } 我自己測試都吻合阿 他卻說我wrong answer = = 是怎麼回事阿 output格式錯誤嗎? 感謝指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.70.246.124

08/05 23:33,
直接 cin/cout 就好。不可輸出與題目要求無關的東西
08/05 23:33

08/05 23:38,
對了 我還想問一下 她INPUT是一次一組嗎 還是?
08/05 23:38

08/05 23:39,
因為想說不是一次一組要怎麼知道要WHILE多少次= =
08/05 23:39

08/05 23:39,
謝謝1樓喔
08/05 23:39

08/05 23:40,
通常很多組, 有的讀到 EOF, 或是特定筆數為止
08/05 23:40

08/05 23:40,
題目會明確給你
08/05 23:40
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.70.246.124

08/05 23:52, , 1F
小心 x > y
08/05 23:52, 1F

08/05 23:53, , 2F
以及注意原推文一樓
08/05 23:53, 2F

08/05 23:53, , 3F
他是指你的 main 第一行那種東西
08/05 23:53, 3F

08/05 23:54, , 4F
不懂 >"<
08/05 23:54, 4F

08/06 00:05, , 5F
仔細看 sample input、sample output
08/06 00:05, 5F

08/06 00:07, , 6F
就是你只能輸出題目要求的,任何一點多的都不行
08/06 00:07, 6F

08/06 00:08, , 7F
樓上是指他INPUT一次4組這樣嗎?
08/06 00:08, 7F

08/06 00:08, , 8F
BTW, 再提醒你一下,UVa 的題目難度跟題號沒有關係 :P
08/06 00:08, 8F

08/06 00:09, , 9F
我的寫法是一次輸入一組結束
08/06 00:09, 9F

08/06 00:09, , 10F
不是,我是說你不用輸出「請輸入xxx」或「程式結束」這類
08/06 00:09, 10F

08/06 00:10, , 11F
那程式結束那個要怎麼刪掉啊??
08/06 00:10, 11F

08/06 00:10, , 12F
08/06 00:10, 12F

08/06 00:10, , 13F
SYSTEM("PAUSU");嗎?
08/06 00:10, 13F

08/06 00:11, , 14F
THX!!
08/06 00:11, 14F
文章代碼(AID): #1CMjukvB (C_and_CPP)
文章代碼(AID): #1CMjukvB (C_and_CPP)