Dima worked all day and wrote down on a long paper strip his favorite number nn consisting of ll digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.

To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.

Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.

Input

The first line contains a single integer ll (2≤l≤1000002≤l≤100000) — the length of the Dima's favorite number.

The second line contains the positive integer nn initially written on the strip: the Dima's favorite number.

The integer nn consists of exactly ll digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.

Output

Print a single integer — the smallest number Dima can obtain.

Examples
input

Copy
7
1234567
output

Copy
1801
input

Copy
3
101
output

Copy
11
Note

In the first example Dima can split the number 12345671234567 into integers 12341234 and 567567. Their sum is 18011801.

In the second example Dima can split the number 101101 into integers 1010 and 11. Their sum is 1111. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.

题解:从中间往两边分出两个分支,取最优解即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string cal(string a,string b)//字符串加法,模拟数的加法即可
{
string ans="";
int pos1=a.size()-,pos2=b.size()-;
int last=,x=;
while(){
if(pos1<&&pos2<)break;
if(pos1<&&pos2>=){
while(pos2>=){
x=b[pos2--]-''+last;
if(x>=){
last=x/;
x%=;
}
else
last=;
ans+=x+'';
}
break;
}
if(pos2<&&pos1>=){
while(pos1>=){
x=a[pos1--]-''+last;
if(x>=){
last=x/;
x%=;
}
else
last=;
ans+=x+'';
}
break;
}
x=a[pos1--]-''+b[pos2--]-''+last;
if(x>=){
last=x/;
x%=;
}
else
last=;
ans+=x+'';
}
if(last)
ans+=last+'';
return ans;
}
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int pos1=n/,pos2=n/+;
while(s[pos1]==''&&pos1>)pos1--;
while(s[pos2]==''&&pos2<n-)pos2++; string a=s.substr(,pos1);
string b=s.substr(pos1,s.size());
string ans=cal(a,b);
reverse(ans.begin(),ans.end());
string aa=s.substr(,pos2);
string bb=s.substr(pos2,s.size());
string anss=cal(aa,bb);
reverse(anss.begin(),anss.end());
if(s[pos2]=='')//特判后一部分不能分的情况,如果想到的话,这个题比赛的时候就能做出来了丫丫丫
return cout<<ans<<endl,;
if(ans.size()<anss.size())cout<<ans<<endl;
else if(ans.size()>anss.size())cout<<anss<<endl;
else{
if(ans<anss)
cout<<ans<<endl;
else
cout<<anss<<endl;
}
return ;
}

B. Split a Number(字符串加法)的更多相关文章

  1. Codeforces Round #567 (Div. 2)B. Split a Number (字符串,贪心)

    B. Split a Number time limit per test2 seconds memory limit per test512 megabytes inputstandard inpu ...

  2. Codeforces C. Split a Number(贪心大数运算)

    题目描述: time limit per test 2 seconds memory limit per test 512 megabytes input standard input output ...

  3. Codeforces Round #567 (Div. 2) B. Split a Number

    Split a Number time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  4. delphi string.split 按照任意字符串分割语句

    delphi string.split 按照任意字符串分割语句 1.就是把一个指定的字符串用指定的分割符号分割成多个子串,放入一个 TStringList 中 function ExtractStri ...

  5. Split the Number(思维)

    You are given an integer x. Your task is to split the number x into exactly n strictly positive inte ...

  6. JS对象 字符串分割 split() 方法将字符串分割为字符串数组,并返回此数组。 语法: stringObject.split(separator,limit)

    字符串分割split() 知识讲解: split() 方法将字符串分割为字符串数组,并返回此数组. 语法: stringObject.split(separator,limit) 参数说明: 注意:如 ...

  7. Java split 根据指定字符串分隔成list数组的用法

    String str="Java string split test";      String[] strarray=str.split(" ");//得到一 ...

  8. Swift3.0 split函数切割字符串

    我们先看函数的原型: public func split(separator: Self.Iterator.Element, maxSplits: Int = default, omittingEmp ...

  9. ACdream 1188 Read Phone Number (字符串大模拟)

    Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Sub ...

随机推荐

  1. IDEA创建新文件时自动生成时间和作者

    打开设置,打开下图的选项并且输入 /** * @author 你的名字 * @date ${DATE} ${TIME} */

  2. nginx重写常用写法

    1.将http协议重写成https协议: (用户用http进行访问,但后端是https),则可添加80 http端口监听,然后进行https rewrite; server {     listen ...

  3. P3241 [HNOI2015]开店

    题解:动态点分治 建立点分树 每个点维护点分树子树内节点到这个节点和父亲节点距离的前缀和 二分查找锁定合法区间 对每个祖先分治中心查询路径和然后减去不合法子树内的路径和 注意:求大量LCA时用树剖 不 ...

  4. sql注入入门--基本命令

    本文转载自http://blog.csdn.net/zgyulongfei/article/details/41017493 本文仅献给想学习渗透测试的sqlmap小白,大牛请绕过. > > ...

  5. 寒假day09

    今天看了论文的结构,定下了毕设论文的框架,刷了剑指offer的部分算法题.

  6. Maven--mirror 和 repository

    参考:http://blog.csdn.net/isea533/article/details/22437511   http://www.cnblogs.com/xdouby/p/6502925.h ...

  7. Linux下idea由于缺少相关权限导致的tomcat ERROR

    昨天一天都在倒腾两个系统,也是醉了. 不过还好,系统修好了,在ubuntu下重新安装idea后,出现了这个错误: Intellij Idea Tmocat Error running Tomcat: ...

  8. MYSQL8用户创建及权限操作

    MYSQL8创建.删除用户和授权.消权操作 上网找过资料说要进入mysql数据库在进行这些操作,我试了发现不进数据库和进入mysql数据库效果都一样 网上有的直接创建并赋权,像酱紫的: grant a ...

  9. Dynamics CRM - 不同类型字段在 Plugin 里的赋值方式

    在编写 Plugin 代码之前,我们可以需要用 SDK bin 目录下的 CrmSvcUtil.exe 来将 CRM Site 上所有的 Entity 转换成类,而 Entity 里的 Field 也 ...

  10. 201604-2 俄罗斯方块 Java

    大家谁能帮我看看是哪里不对,提交到系统中是0分,在Eclipse中可以得出例子中的结果 思路: 题目中有两个关键点:如何模拟下落的过程,如何判断方块下落在哪里停止. 在数据的存储上,需要保存整个&qu ...