fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, howMany = 0, j = 1;
  6. int v[10], samePosition[10];
  7. for (int i = 1; i <= n; ++i) {
  8. cin >> v[i];
  9. }
  10. for (int i = 1; i <= n; ++i) {
  11. if (v[i] == i) {
  12. samePosition[j] = v[i];
  13. ++j;
  14. ++howMany;
  15. }
  16. }
  17. for (int i = 1; i <= howMany; ++i) {
  18. cout << samePosition[i] << " ";
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 5284KB
stdin
9
1 2 3 6 8 9 7 9 10
stdout
Standard output is empty