Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

what is wrong in my code...? it is working without any error in my machine.

$
0
0

include<iostream>

using namespace std;

int main() { int n,t=1,pos=1; cin>>n; int A[n+1];int P[n+1]; int C[n+1];int B[n+1]; for(int i=1;i<=n;i++) {cin>>A[i]; C[i]=0;P[i]=0; }

for(int k=1;k<=n;++k) { if(C[k]==0) { P[pos++]=k; C[k]=1; for(int i=A[k];i<=n;i=A[i]) { B[t++]=i; C[i]=1; if(i==k) break;

      }

  }

} cout<<pos-1<<endl; int a=1,j=1; while(a<pos) { cout<<P[a]; for(;j<=n;++j) { cout<<B[j]; if(P[a]==B[j]) { j++; cout<<endl; break; }

  }
  a++;

} return 0; }


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>