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. Locale

    1. Locale 概述 2. Windows 区域设置 3 Linux Locale 3.1 Linux Locale 语言环境名称格式 3.2 常用区域描述(简写)日期习惯 3.3 日期显示格式 ...

  2. CentOS7中Tomcat的安装和配置

    Tomcat运行需要设置JRE目录,全局变量配置,请参见: Linux下JDK的安装和配置   当然也可以直接修改Tomcat的配置文件,请自行度娘   1.下载并解压 请先去官网找到需要下载的tom ...

  3. Kubernetes 1.17.2 高可用部署

    20.0.0.200    10.0.0.200 bs-k8s-master01 管理节点 2c2g 20.0.0.201    10.0.0.201 bs-k8s-master02 管理节点 2c2 ...

  4. 搭建 nginx + rtmp 媒体服务器笔记

    工作需要搭建一个流媒体服务器,用来接收前端推过来的视频流,达到实时保存的目的. 具体步骤网上已经比较详细了 可以参考下面这个文档参考文档 https://www.cnblogs.com/monjeo/ ...

  5. 【快学springboot】9.使用 @Transactional 注解配置事务管理

    介绍 springboot对数据库事务的使用非常的方便,只需要在方法上添加@Transactional注解即可.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的 ...

  6. day16-Python运维开发基础(os / os.path / shutil模块)

    1. OS模块与shutil模块 os :新建/删除shutil: 复制/移动 # ### os模块 与 shutil模块 """ os 新建/删除 shutil 复制/ ...

  7. re模块补充 configparse模块

    import rere.findall("(?:abc)+","abcabcabc")--->['abcabcabc'] import configpar ...

  8. Jsp有哪些内置对象?作用分别是什么?

    Page,pageContext,request,response,session,application,out,config,exception Page指的是JSP被翻译成Servlet的对象的 ...

  9. WebApi如何接收前台传递过来的数组

    var ids = ["111", "222", "333"];$.ajax({ url: host + '/User/deleteByID ...

  10. windows10安装.netframework3.5

    先挂载,看看挂载到哪个盘了,假设是I盘 然后按住shift 点鼠标右键,打开powershell,运行下面命令: dism.exe /online /enable-feature /featurena ...