【PAT乙級】1025 反轉鏈錶 代碼可以通過測試用例但是一旦提交全部答案錯誤?

CSDN問答 2022-01-07 23:34:57 阅读数:946

pat 提交 答案
#include<iostream>#include<string>#include<vector>using namespace std;int main(){ string add; int fadd = 0, num = 0, k = 0,nadd=0,n=0,flag=0; cin>>fadd>>num>>k; vector<string> arr(num*5); for (int i = 0; i < num; i++) { cin>>add>>n>>nadd; arr[n]=add; } for (int j = k; j <= num; j=j+k) { for (int i = j; i >j-k; i--) { ++flag; if (flag==k+1) { cout<<arr[i]<<endl; } if (flag!=num&&i!=1) { cout<<arr[i]<<" "<<i<<" "<<arr[i-1]<<endl; }else if (flag==num) { cout<<arr[i]<<" "<<i<<" "<<"-1"; }else if (flag!=num&&i==1) { cout<<arr[i]<<" "<<i<<" "; } } } for (int i = num-num%k+1; i <=num; i++) { ++flag; if (i == num-num%k+1) { cout<<arr[i]<<endl; } if (flag<num) cout<<arr[i]<<" "<<i<<" "<<arr[i+1]<<endl; else cout<<arr[i]<<" "<<i<<" "<<"-1"<<endl; } return 0;}

就是運行測試用例的時候沒有任何錯誤,試著運行了網友提供的其他測試用例也沒問題,可是一提交代碼全錯,我自己看了好久沒發現代碼哪裏有問題,有沒有大神為我指點迷津?




采納答案:

貼的代碼有點醜大家不要介意。。。



其他答案2:

版权声明:本文为[CSDN問答]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/01/202201072334567676.html