ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1053. Пиноккио

why compilation error? if both gcc and intel c/c++ can compile
Послано junmin 2 окт 2008 22:57
#include <stdio.h>
#include <stdlib.h>

int compare(const int *, const int *);
int gcd(int, int);

int main(void)
{
  int size = 0,counter = 0;
  scanf("%d",&size);
  int ls[size];
  int * pointer = ls;
  while(counter < size)
    {
      scanf("%d", pointer++);
      counter++;
    }
  qsort(ls, size, sizeof(int), compare);
  int x = ls[0];
  while(--counter > 0)
    {
      x = gcd(x, ls[counter]);
    }
  printf("%d", x);
  return 0;
}

int gcd(int small, int big)
{
  if (small == 0) return big;
  return gcd(big % small, small);
}

int compare(const int *p1, const int *p2)
{
  int x = *p1;
  int y = *p2;
  if(x < y)
    {
      return -1;
    }
  else
    {
      return 1;
    }
}

=====================

2904ea07-b44d-48c6-ba40-3b3f94228782
2904ea07-b44d-48c6-ba40-3b3f94228782(11): error: declaration may not appear after executable statement in block
    int ls[size];
    ^

2904ea07-b44d-48c6-ba40-3b3f94228782(11): error: expression must have a constant value
    int ls[size];
           ^

2904ea07-b44d-48c6-ba40-3b3f94228782(12): error: declaration may not appear after executable statement in block
    int * pointer = ls;
    ^

2904ea07-b44d-48c6-ba40-3b3f94228782(18): warning #167: argument of type "int (*)(const int *, const int *)" is incompatible with parameter of type "int (__cdecl *)(const void *, const void *)"
    qsort(ls, size, sizeof(int), compare);
                                 ^

2904ea07-b44d-48c6-ba40-3b3f94228782(19): error: declaration may not appear after executable statement in block
    int x = ls[0];
    ^

2904ea07-b44d-48c6-ba40-3b3f94228782(47): warning #1: last line of file ends without a newline
  }
   ^

compilation aborted for 2904ea07-b44d-48c6-ba40-3b3f94228782 (code 2)


=============

junmin@thinking ~/workspace/otros/ACM $ gcc --version
gcc (Gentoo 4.3.1-r1 p1.1) 4.3.1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

junmin@thinking ~/workspace/otros/ACM $ icc --version
icc (ICC) 10.1 20080801
Copyright (C) 1985-2008 Intel Corporation.  All rights reserved.


thanks!!!!

Edited by author 02.10.2008 23:11
Re: why compilation error? if both gcc and intel c/c++ can compile
Послано Burunduk1 3 окт 2008 12:12
Your code:
int compare(const int *, const int *);
Right code:
int compare(const void *, const void *);

Your code:
int ls[size];
Right code:
int *ls = new int[size];

I wonder, where have you found C/C++ compiler which can successful compile it. =)
My MinGW-gcc 3.4.2, Visual 2003, Visual 2005, Mandriva-gcc 3.4.2 say "Compilation error"