2015-03-28 01:34:38

总结:这场用来练java了... 

  赛中搞了A,B,C,然后开始坑E题... 暴力DFS结果TLE了... rank 300+(unofficial)

  赛后用c++补了D、E...(因为发现java的JSTL有点烦...)

A:模拟题,从左到右扫一遍,维护一个计数数组即可。

 1 import java.util.Scanner;
 2 
 3 public class Main{
 4     public static void main(String[] args){
 5         Scanner in = new Scanner(System.in);
 6         int n = in.nextInt();
 7         String str = in.next();
 8         char[] s = new char[str.length()];
 9         s = str.toCharArray();
10         int[] cnt = new int[30];
11         int sum = 0;
12         for(int i = 0; i < str.length(); ++i){
13             if(s[i] >= 'a' && s[i] <= 'z'){
14                 cnt[(int)(s[i] - 'a')]++;
15             }
16             else{
17                 int id = (int)(s[i] - 'A');
18                 if(cnt[id] == 0) sum++;
19                 else cnt[id]--;
20             }
21         }
22         System.out.println(sum);
23         in.close();
24     }
25 
26 }
View Code

相关文章: