FZU 1913 Easy Comparison 解题报告

题意:字符串排序后不再自己位置上的有几个

解法:sort……

//Memory: 228 KB		
//Time: 0 MS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
int a[4];
int main()
{
    //freopen("/home/moor/Code/input.txt","r",stdin);
    int ncase,len;
    string a,b;
    scanf("%d",&ncase);
    for(int h=1;h<=ncase;++h)
    {
        int ans = 0;

        cin>>len>>a;
        b = a;
        sort(b.begin(),b.end());
        for(int i = 0; i < len; i++)
            if(a[i]!=b[i]) ans++;
        printf("Case %d: %d\n",h,ans);
    }
}


你可能感兴趣的:(FZU 1913 Easy Comparison 解题报告)