[ create a new paste ] login | about

Link: http://codepad.org/fARSxPk9    [ raw code | output | fork ]

C, pasted on Jun 30:
#include<stdio.h>
int p[100005];
int main(void)
{
    int n, k, temp=0, ans=0;
    scanf("%d %d", &n, &k);
    for(int i=0;i<n;i++) scanf("%d", &p[i]);
    for(int i=0;i<n;i++){
        if(temp+k==p[i]){
            temp = p[i];
            ans++;
            if(temp==p[n-1]) ans--; //記得最終點
        }
        else if(temp+k<p[i]){
            temp = p[i-1];
            ans++;
            if(temp==p[n-1]) ans--; //記得最終點
        }
    }
    if(temp+k<p[n-1]) printf("The Legend Falls.\n");
    else printf("%d\n", ans);
    return 0;
}


Output:
1
2
3
4
5
In function 'main':
Line 7: error: 'for' loop initial declaration used outside C99 mode
Line 8: error: redefinition of 'i'
Line 7: error: previous definition of 'i' was here
Line 8: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: