A. Vitaliy and Pie

题目:奇数位是钥匙(已经有的钥匙),偶数位是门,钥匙开门,开过门的钥匙不能带在身上,计算开了n个门还要另外带几把钥匙

import java.util.Scanner;


public class A525 {
void solve(){
    Scanner sc=new Scanner(System.in);
    int n= sc.nextInt();
    char[] str =sc.next().toCharArray();
    int len=str.length;
    int[] lower=new int[27];
    for(int i=0;i<27;i++){
        lower[i]=0;
    }
    int result=0;
    for(int i=0;i<len;i++){

        if(str[i]>='a' && str[i]<='z'){
// System.out.println(str[i]);
// System.out.println(str[i]-'a');
            int temp=str[i]-'a';
            lower[temp]=lower[temp]+1;
        }else if(str[i]>='A' && str[i]<='Z'){
            int temp=str[i]-'A';
            if(lower[temp]>0){
                lower[temp]=lower[temp]-1;
            }else if(lower[temp]==0){
                result=result+1;
            }

        }
    }
    System.out.println(result);
}
public static void main(String [] args){
    new A525().solve();
}
}

你可能感兴趣的:(A. Vitaliy and Pie)