|
|
вернуться в форумHELP ME, PLEASE ! I CAN'T GET ACCEPTED A HALF OF THE YEAR. I DON'T KNOW, WHAT I DO WRONG. HERE IS MY SYMPLE C++ PROGRAMM: #include <iostream.h> const Nmax = 8000; // 7500; int N; int a[Nmax]; int i1[Nmax]; int i2[Nmax]; void Solve(); void main() { int i,j; N = 1; do { if (cin.eof()) break; cin >> a[N]; a[N++] --; } while (1); N--; Solve(); int b[Nmax]; int k; for (int ii=0; ii<N; ii++) { cout << ii+1 << ":"; k = 0; for (j=0; j<N-1; j++) { if (i1[j]==ii) b[k++] = i2[j]+1; else if (i2[j]==ii) b[k++] = i1[j]+1; } for (i=0; i<k-1; i++) for (j=i+1; j<k; j++) if (b[i]>b[j]) { int t = b[i]; b[i] = b[j]; b[j] = t; } for (i=0; i<k; i++) cout << " " << b[i]; cout << endl; } } void Solve() { int i,j; int c[Nmax]; for (i=0; i<N; i++) c[i] = 0; c[a[N-1]] = 1; int k = 0; for (i=N-1; i>=0; i--) { if (i>0 && !c[a[i-1]]) { c[a[i-1]] = 1; i1[k] = a[i-1]; i2[k++] = a[i]; } else { for (j=N-1; j>=0; j--) if (!c[j]) { c[j] = 1; i1[k] = j; i2[k++] = a[i]; break; } } } } THANK YOU ! |
|
|