[关闭]
@PaulGuan 2016-10-18T05:39:20.000000Z 字数 275 阅读 574

A - Presents 题解

算法 题解


题目大意

给定一串数,索引从1到n,交换索引和数值,然后输出。

分析

用另一个数组f[ai]=i;即可。

代码

  1. #include<iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. int num[102];
  7. int n,l;
  8. cin >> n;
  9. for (int i = 1; i <= n; i++)
  10. {
  11. cin >> l;
  12. num[l] = i;
  13. }
  14. for (int i = 1; i <= n; i++)
  15. {
  16. cout << num[i];
  17. if (i == n)
  18. continue;
  19. cout << " ";
  20. }
  21. cout << endl;
  22. return 0;
  23. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注