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 1024. Permutations

Help me!!! I have a Compilation ERROR!
Posted by Куделевский Женя 14 Apr 2005 18:06
My Source:

#include <stdio.h>

int nok(int a,int b)
{
    int a1=a,b1=b;
    while (a!=b)
    {
        if(a>b) a-=b;
        else b-=a;
    }
    return(a1*b1/a);
}

int main()
{
    int n,per[1010];
    int a[1010];

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

    for(i=1;i<=n;i++)
    {
        if(a[i]==0)
        {
            a[i]=1;
            int pos = per[i];
            while(pos!=i)
            {
                pos = per[pos];
                a[i]++;
            }
            pos = per[i];
            while(pos!=i)
            {
                a[pos] = a[i];
                pos = per[pos];
            }
        }
    }

    for(i=2;i<=n;i++)
    {
        a[i] = nok(a[i-1],a[i]);
    }
    printf("%d",a[n]);

    return(0);
}
Re: Help me!!! I have a Compilation ERROR!
Posted by Cybernetics Team 14 Apr 2005 18:28
"for (int i = 0..." isn't accepted, declare i separately