A1067 Sort with Swap(0, i)(25分)PAT甲级

A1067 Sort with Swap(0, i)(25分)PAT甲级 ,第1张

Input Specification:

Each input file contains one test case, which gives a positive N (≤105) followed by a permutation sequence of {0, 1, ..., N−1}. All the numbers in a line are separated by a space.

Output Specification:

For each case, simply print in a line the minimum number of swaps need to sort the given permutation.

Sample Input:
10
3 5 7 2 6 4 9 0 8 1
Sample Output:
9
代码如下:
#include
using namespace std;
int a[100010];//数字i所在的位置
int main()
{
    int n,t,count=0;
    cin>>n;
    for(int i=0;i>t;
        a[t]=i;//数字t在第i个位置上
    }
    for(int i=0;i
运行结果如下:

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/875561.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-13
下一篇2022-05-13

发表评论

登录后才能评论

评论列表(0条)