Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

傻逼了,==写成了=,wa了一次,题水我更水,附ac代码

Posted by 1004115224 at 2012-08-17 20:31:17 on Problem 1674
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int a[10001],b[10001];
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i];
        }
        sort(b,b+n);
        int v=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]!=b[i])
            {
                for(int j=i+1;j<n;j++)
                {
                    if(a[j]==b[i])
                    {
                        swap(a[i],a[j]);
                        v++;
                        break;
                    }
                }
            }
        }
        cout<<v<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator