A. Case of the Zeros and Ones
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.

Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose any two adjacentpositions
in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length n - 2 as
a result.

Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.

Input

First line of the input contains a single integer n (1 ≤ n ≤ 2·105),
the length of the string that Andreid has.

The second line contains the string of length n consisting only from zeros and ones.

Output

Output the minimum length of the string that may remain after applying the described operations several times.

Sample test(s)
input
4
1100
output
0
input
5
01010
output
1
input
8
11101111
output
6
Note

In the first sample test it is possible to change the string like the following: .

In the second sample test it is possible to change the string like the following: .

In the third sample test it is possible to change the string like the following: .

Codeforces喜欢把一些很简单的答案隐藏在复杂的问题之下,因为0和1总会相邻啊。。。所以这题就是求0和1的差的绝对值。。。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; string tes;
int n;
int n0;
int n1; int main()
{
//freopen("i.txt", "r", stdin);
//freopen("o.txt", "w", stdout); int i; n0 = 0;
n1 = 0; cin >> n;
cin >> tes;
for (i = 0; i < n; i++)
{
if (tes[i] == '0')
n0++;
else
n1++;
}
cout << abs(n0 - n1) << endl;
//system("pause");
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Codeforces 556A:Case of the Zeros and Ones的更多相关文章

  1. 【52.49%】【codeforces 556A】Case of the Zeros and Ones

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. Codeforces 556 A Case of the Zeros and Ones

    A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...

  3. Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  4. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

  5. Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏

    A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...

  6. A. Case of the Zeros and Ones----解题报告

    A. Case of the Zeros and Ones Description Andrewid the Android is a galaxy-famous detective. In his ...

  7. android switch语句报错:case expressions must be constant expressions

    今天无意中碰见了   case expressions must be constant expressions 的问题 写了一个 switch(item.getItemId()) { case R. ...

  8. SQL Server -- 回忆笔记(四):case函数,索引,子查询,分页查询,视图,存储过程

    SQL Server知识点回忆篇(四):case函数,索引,子查询,分页查询,视图,存储过程 1. CASE函数(相当于C#中的Switch) then '未成年人' else '成年人' end f ...

  9. SQL进阶1:case表达式的用法示例

    一:case表达式的用法 1.SQL中的case表达式的作用是用来对"某个变量"进行某种转化,通常在select字句中使用,举个例子: 不能看出,case表达式很像我们的if el ...

随机推荐

  1. Java-用星号打印菱形

    打印如图所示菱形9行9列(提示可以将菱形分成上下两个三角形,分析每行空格数和星号个数的关系) 代码如下: package com.homework.lhh; public class Ex20 { p ...

  2. [原]HelloWorld

    几乎所有程序员的编程都是从写HelloWorld开始的,作为新开的Blog我还是照旧吧. 首先需要肯定的是博客园的管理员做事很高效,我是22:08申请的,结果22:32就审核通过了,理论上讲申请审核时 ...

  3. vue cli3.0打包

    1.vue cli3.0需要在项目根目录下配置webpack  包括反向代理以及打包文件路径 const webpack = require("webpack"); module. ...

  4. zabbix通过ipmi传感器监控浪潮服务器的硬件信息

    一:实验对象 操作系统版本:centos7.6 监控对象:通过服务器传感器获取到的所有在使用的硬件信息 zabbix版本: 4.0.14二:zabbix介绍 zabbix适合中小型企业.大型企业的用户 ...

  5. pytorc人工神经网络Logistic regression与全连接层

    //2019.10.08神经网络与全连接层1.logistics regression逻辑回归的思想是将数据利用激活函数sigmoid函数转换为0-1的概率,然后定义一定的阈值0.5,大于阈值则为一类 ...

  6. Jenkins安装 maven插件

    Maven Artifact ChoiceListProvider (Nexus)Maven Metadata Plugin for Jenkins CI serverMaven Release Pl ...

  7. lnmp一键安装的缺点???

    自己尝试几次在新的服务器上安装lnmp环境,每次都是一键安装,然后在/home/wwwroot/default目录下放对应的PHP文件就Ok了,很方便.其实也尝试过用命令行,就是很多命令的那种安装,中 ...

  8. Mp3下载

  9. 【剑指Offer面试编程题】题目1523:从上往下打印二叉树--九度OJ

    题目描述: 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 输入: 输入可能包含多个测试样例,输入以EOF结束. 对于每个测试案例,输入的第一行一个整数n(1<=n<=1000, ...

  10. pythono整数和字符串魔法方法

    1.整数(int) a = 1 b = 2 c = 3 d = 4 e = 5u a1 = a.bit_length() b1 = b.bit_length() c1 = c.bit_length() ...