关闭

FZU 1913 (13.12.05)

559人阅读 评论(0) 收藏 举报
分类:
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;
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:90756次
    • 积分:2372
    • 等级:
    • 排名:第15732名
    • 原创:152篇
    • 转载:0篇
    • 译文:0篇
    • 评论:11条
    博客专栏
    最新评论