腾讯暑期实习生机试题 - 01串 java

 

import java.util.Scanner;

/**
 * @program: 个人demo
 * @description: 每次都是pass
 * @author: Mr.Hu
 * @create: 2019-03-29 19:07
 */
public class OJ {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {//注意while处理多个case
            int n = in.nextInt();
            int n_1=0,n_0=0;
            String s=in.next();
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i)=='0') n_0++;
                else n_1++;
            }
            System.out.println(Math.abs(n_0-n_1));
        }
    }
}

 

相关文章:

  • 2022-12-23
  • 2021-09-03
  • 2021-06-06
  • 2022-12-23
  • 2021-07-18
猜你喜欢
  • 2021-11-09
  • 2021-10-08
  • 2022-01-11
  • 2021-12-12
相关资源
相似解决方案