[問題] ITSA第24次第4題

看板C_and_CPP作者 (美麗新世界)時間11年前 (2014/05/03 11:07), 編輯推噓1(105)
留言6則, 3人參與, 最新討論串1/4 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) iostream 問題(Question): http://truth.bahamut.com.tw/s01/201405/2827e54fa6e7853d0a80ffab1381d289.JPG
錯誤結果(Wrong Output): http://truth.bahamut.com.tw/s01/201405/08372dfa3afb99c7500459ef7f41b9e9.JPG
程式碼(Code):(請善用置底文網頁, 記得排版) #include<iostream> using namespace std; int main(){ char (*a)[50] = new char[100000][50]; char (*tmp)[50] = new char[100000][50]; long long (*b)= new long long[100000]; long long (*c)= new long long[100000]; long long d; cin>>d; for(int i=0;i<d;i++){ cin>>a[i]; cin>>b[i]; cin>>c[i]; } for(int j=0;j<d-1;j++){ for(int i=0;i<d;i++){ if(b[i]<b[i+1]){ strcpy(tmp[i],a[i]); strcpy(a[i],a[i+1]); strcpy(a[i+1],tmp[i]); swap(b[i],b[i+1]); swap(c[i],c[i+1]); } if(b[i]==b[i+1]&&c[i]<c[i+1]){ strcpy(tmp[i],a[i]); strcpy(a[i],a[i+1]); strcpy(a[i+1],tmp[i]); swap(b[i],b[i+1]); swap(c[i],c[i+1]);}}} for(int i=0;i<d;i++){ cout<<a[i]<<" ";} delete [] a; delete [] tmp; delete [] b; delete [] c; return 0;} 補充說明(Supplement): 這是我的執行畫面 http://truth.bahamut.com.tw/s01/201405/5baabcea5be42fd24b659947cde82090.JPG
是我搞錯題目意思還是哪裡打錯了嗎 測試沒問題阿(應該巴.) 傳上去卻一直說錯誤 ptt好難用喔 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.86.201.154 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1399115250.A.949.html

05/03 19:10, , 1F
1. 以空白隔開意味著最後一個人之後不應有空白
05/03 19:10, 1F

05/03 19:10, , 2F
2. 最後必須有換行字元 '\n'
05/03 19:10, 2F

05/03 20:06, , 3F
還是錯誤哈哈
05/03 20:06, 3F

05/03 22:47, , 4F
我覺得解法不夠漂亮,寫一個sort函式,然後先對人氣排序
05/03 22:47, 4F

05/03 22:48, , 5F
再對薪資排序即可,不必比較薪資是否相等
05/03 22:48, 5F

05/03 23:56, , 6F
可是應該不影響結果巴,但我傳上去他都說我錯誤答案,!@$@!
05/03 23:56, 6F
文章代碼(AID): #1JPCtob9 (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1JPCtob9 (C_and_CPP)