kvtoraman's blog

By kvtoraman, 12 years ago, In English

In this submisson: 2431151 In that line: "if(hour[i]==hour[i-1]&&min[i]==min[i-1]){"

In the beginning, i=0 so that hour[i-1] means hour[-1].Can someone please explain how can this pass the pretests?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
12 years ago, # |
  Vote: I like it +2 Vote: I do not like it

what can i do?

»
12 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Well I try run this code

#include <iostream>
using namespace std;
int main() {
    int arr[100];
    cout << arr[-1] << endl;
    return 0;
}

on Costum Test in codeforces. It return 0 and did not give runtime error. I don't know what they use when compiling, but maybe this can explain why that code pass the pretest

UPDT I mean it produce output 0 and did not give runtime error

»
12 years ago, # |
  Vote: I like it +10 Vote: I do not like it

In C++, a[i] means *(a+i). This code accesses the memory cell located 4 bytes before than hour[0].