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. Python爬虫的简单入门(一)

    Python爬虫的简单入门(一) 简介 这一系列教学是基于Python的爬虫教学在此之前请确保你的电脑已经成功安装了Python(本教程使用的是Python3).爬虫想要学的精通是有点难度的,尤其是遇 ...

  2. Codeforces 1296C - Yet Another Walking Robot

    题目大意: 给定一个机器人的行走方式 你需要取走一段区间 但要保证取走这段区间后机器人最终到达的终点位置是不变的 问这段区间最短时是哪一段 解题思路: 易得,如果重复走到了某些已经走过的点,那么肯定就 ...

  3. caffe + ssd网络训练过程

    參考博客:https://blog.csdn.net/xiao_lxl/article/details/79106837 1获取源代码:git clone https://github.com/wei ...

  4. python全局变量、回调函数

    1.python全局变量相关概念及使用 来自菜鸟教程上的例子: http://www.runoob.com/python3/python3-function.html 一.python入参需要注意地方 ...

  5. javacv 设置帧率(续)

    前文地址:https://www.cnblogs.com/svenwu/p/9663038.html 前文已经对大多数正常情况可以支持了,但是我最近处理一些公司的视频流,发现一些坑爹的情况 每次给的视 ...

  6. h5-全屏插件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 深入JVM(一)JVM指令手册

    本文按照如下思维导图组织 1. 栈和局部变量操作 1.1 将常量压入栈的指令 aconst_null 将null对象引用压入栈iconst_m1 将int类型常量-1压入栈iconst_0 将int类 ...

  8. F5双机冗余配置

    转自:https://blog.51cto.com/dynamic/769888本文作者:CTO_LiuJinFeng 1. 配置管理接口-IP 前面文章中没提到如何配置IP,现在开始来配置. 登录- ...

  9. 吴裕雄--天生自然Django框架开发笔记:Django简介

    Python下有许多款不同的 Web 框架.Django是重量级选手中最有代表性的一位.许多成功的网站和APP都基于Django. Django是一个开放源代码的Web应用框架,由Python写成. ...

  10. Linux&Win双系统下时间显示不正常的问题

    于近期开始研究Linux,目前用的是ubuntu.本想着用Linux搞事情,没想到却被Linux搞了. 我安装的是双系统,Linux&windows的组合.相信刚开始用双系统的小伙伴们一定会碰 ...