FZU 1913 (13.12.05)

原创 2013年12月05日 22:03:58
Problem 1913 Easy Comparison

Accept: 394    Submit: 511
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

Given a string S, your task is to simulate the following operations. At first, you should sort it by lexicographic order and generate an order string S’. Then, you should compare S’ with S character by character. Finally, you should output the number of different characters between S’ and S.

For example, if the original string S is “ACMICPC”, when we sort this string we could get a new string S’ “ACCCIMP”. Then we compare these two strings, we could find out that only two characters ‘A’ whose index is 0 and ‘C’ whose index is 1 are the same (index from 0), so there are 5 different characters.

Input

The first line of the input contains an integer T (T <= 10), indicating the number of cases. Each case begins with a line containing one integer n (1 <= n <= 100), the length of the string S. The next line contains the string, consisting of characters ‘A’ to ‘Z’.

Output

For each test case, print a line containing the test case number (beginning with 1) and the number of different characters between the two strings as said above.

Sample Input

42AC6ACCEPT7ACMICPC10FZUACMICPC

Sample Output

Case 1: 0Case 2: 0Case 3: 5Case 4: 10

Source

2010年全国大学生程序设计邀请赛(福州)


水题。。。

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

char s1[105];
char s2[105];

int main() {
    int T;
    int cas = 0;
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);
        getchar();
        gets(s1);
        strcpy(s2, s1);
        sort(s2, s2+n);
        int count = 0;
        for(int i = 0; i < n; i++) {
            if(s1[i] != s2[i])
                count++;
        }
        printf("Case %d: %d\n", ++cas, count);
    }
    return 0;
}


相关文章推荐

[codevs 1913] 数字梯形问题

[codevs 1913] 数字梯形问题 题解: 本题就是加强版的 [codevs 1033] 蚯蚓的游戏问题。 分别针对三个规则建图、运行最小费用最大流。 规则1:从...

Sicily 1913. Slides

1913. Slides Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description  Ther...

Lava-Lava_1913.exe

  • 2013年03月21日 10:24
  • 12.54MB
  • 下载

ZZULI-1913 小火山的计算能力 【模拟加减】

Contest - 多校训练2(小火山专场)Problem J: 小火山的计算能力Time Limit: 1 Sec Memory Limit: 128 MB Submit: 443 Solve...
  • DTL66
  • DTL66
  • 2016年08月10日 19:39
  • 229

POJ 3486 & HDU 1913 Computers(dp)

POJ 3486 & HDU 1913 Computers(dp)

zoj 1913 Euclid's Game

/* zoj 1913 博弈 思路:递推 举25 7为例,则代码中的vector中为3 1 1 3(大的数对小的数反复取整所得) 不妨把最后的获胜者标记为a,则vecto...

1913: [Apio2010]signaling 信号覆盖

1913: [Apio2010]signaling 信号覆盖Time Limit: 20 Sec Memory Limit: 64 MB Submit: 1420 Solved: 573 [S...

[BZOJ1913][Apio2010]signaling 信号覆盖

计算几何 凹四边形计数
  • hbhcy98
  • hbhcy98
  • 2016年02月12日 22:05
  • 693

Vijos P1913 螺旋矩阵(模拟)

有时候反过来换个角度想问题,往往会变得比较简单。
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:FZU 1913 (13.12.05)
举报原因:
原因补充:

(最多只允许输入30个字)