嘿,我只是想解決的hackerrank但在一些測試用例的代碼超時是一個挑戰,我不知道爲什麼。 This is the challenge。Hackerrank挑戰timout
這裏是我的代碼:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n, k, q;
scanf("%d %d %d",&n,&k,&q);
int qs[q];
int a[n];
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for(int i = 0; i < q; i++){
scanf("%d",&qs[i]);
}
int lastNbr = a[n-1];
for(int i = 0; i < k; i++){
lastNbr = a[n-1];
for(int j = n - 1; j > -1; j--){
a[j] = (j-1 >= 0) ? a[j-1] : lastNbr;
}
}
for(int i = 0; i < q; i++){
printf("%d\n", a[qs[i]]);
}
return 0;
}
那麼,正如你所寫:**你**正試圖解決它。如果**我們**做到了......就不公平了 - - 您有**具體**問題嗎? – Olaf
祕密是你不需要旋轉數組; '%'操作符是你的朋友。 –
@Olaf我的意思是當我提交代碼時,大多數測試用例正在工作,但有些超時。如果你想給我一個提示,說明我的部分代碼發生超時,那將是非常好的。 :) – Nimmi