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. 单变量线性回归(Linear Regression with One Variable)与代价函数

    所谓的单变量线性回归问题就是监督学习的一部分. 通过构建数学模型给出一个相对准确的数值,也就是预测模型,通过将数据通过数学模型,衍生至回归问题 通过以下的几个例子,我们来研究单变量线性回归. 1.王阿 ...

  2. 使用svn时出现Can't switch /XXX/XXX because it is not the repository yet

    问题描述 出现的问题如题目所示. 翻译一下:不能选择这个目录,原因是这个目录还不是svn仓库. 解决办法 这个问题出现的原因是你将项目中的.svn文件夹删除了,一般情况你是可以通过撤销将文件恢复的.如 ...

  3. 12 react 基础 的 css 过渡动画 及 动画效果 及 使用 react-transition-group 实现动画

    一. 过渡动画 # index.js import React from 'react';import ReactDOM from 'react-dom';import App from './app ...

  4. Ubuntu13.04闪屏的问题

    我的电脑Y460,双显切换,win7+ubuntu双系统,就是这个坑爹的双显切换,导致安装ubuntu13.04后屏老闪,网上查阅资料得知是显卡问题,一种是说显卡驱动问题,一种是说双显卡问题,双显卡问 ...

  5. 剑指offer第40题

    package com.yan.offer; /** * 题目描述: * * 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. * * @author Ya ...

  6. 《打造扛得住的MySQL数据库架构》第3章 MySQL基准测试

    3-1 什么是基准测试 测量系统性能,优化是否有效?MySQL基准测试. 定义:基准测试是一种测量和评估软件性能指标的活动,用于建立某个时刻的性能基准,以便当系统发生软硬件 变化时重新进行基准测试以评 ...

  7. MyBatis项目报错:The server time zone value '�й�׼' is unrecognized or represents more than one time zone

    问题来源:在部署Spring + MyBatis项目的时候,运行时报错The server time zone value '�й�׼' is unrecognized or represents m ...

  8. Java开学测试感想

    开学第一堂课就是测试,测试暑假的自学成果,老师说试卷适当提高了难度,所以允许查书和使用网络查询,经过近三个钟头的努力奋斗和痛苦挣扎,我只完成了一小部分的代码,只有简单的set()get()函数,以及简 ...

  9. 吴裕雄--天生自然 JAVA开发学习:Number & Math 类

    int a = 5000; float b = 13.65f; byte c = 0x4a; public class Test{ public static void main(String arg ...

  10. vector内部实现2

    push_back 往动态数组的内部进行添加数据 pop_back 往动态数组的尾部进行删除数据 resize  讲元素的数量len改成num个数量  如果size()变大了,多出来的将用默认构造来创 ...