ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1581. Teamwork

Help me.
Posted by Kornilenko Leonid (KHAI) 3 Feb 2008 00:28
Why compilation error?
Program work and in my compiler there are 0 warnings and 0 errors... I used DevC++ v.4.9.9.2

#include <stdio.h>
int main(void)
{
    int n, i;
    int cur, cntr;

    scanf("%d", &n);
    int arr[n];

    for (i=0; i<n; i++)
    {
        scanf("%d", &arr[i]);
    }

    for (i=0; i<n-1; i++)
    {
        cur = arr[i];
        cntr = 0;
        do
        {
            cntr++;
            i++;
        } while (cur == arr[i]);
        printf("%d %d ", cntr, cur);
        i--;
    }
    return 0;
}
Re: Help me.
Posted by CHIDEMYAN SERGEY 6 Feb 2008 02:53
We can define massiv with n elements such way,when n is const.
#include <stdio.h>
int main(void)
{
int n, i;
int cur, cntr;

scanf("%d", &n);
int arr[n];/*<Error here.Write instead of it:  int *arr=new int[n];*/

for (i=0; i<n; i++)
{
scanf("%d", &arr[i]);
}

for (i=0; i<n-1; i++)
{
cur = arr[i];
cntr = 0;
do
{
cntr++;
i++;
} while (cur == arr[i]);
printf("%d %d ", cntr, cur);
i--;
}
return 0;
}
Good luck!


Edited by author 06.02.2008 02:55