time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Dima worked all day and wrote down on a long paper strip his favorite number n
consisting of l
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 l
(2≤l≤100000
) — the length of the Dima's favorite number.
The second line contains the positive integer n
initially written on the strip: the Dima's favorite number.
The integer n
consists of exactly l
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
(copy)
7 1234567
Output
Copy
(copy)
1801
Input
Copy
(copy)
3 101
Output
Copy
(copy)
11
Note
In the first example Dima can split the number 1234567
into integers 1234 and 567. Their sum is 1801
.
In the second example Dima can split the number 101
into integers 10 and 1. Their sum is 11
. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.
思路:这题要用大数加法,其实这也还好,但有特例,比如
5
11001
要输出1002
我一开始直接遍历从中间到后面的0,然后一直wa,后边我发现了,没时间改,我直接从中间到前后都遍历一次,然后输出小的
然后。。最后六秒极限过题!
代码:
#include
#include
#include
#include
using namespace std;
#define ll long long
#include
#include
#define MAX 150000
int L, M;
int mark;
void add(char a[], char b[], char c[]){
int len1 = strlen(a);
int len2 = strlen(b);
int i, j;
int l = 0;
L = 0;
int temp;
for(i = 0; i < len1/2; i++){
temp = a[i];
a[i] = a[len1-1-i];
a[len1-1-i] = temp;
}//把输入的两个大数都逆序排列,这个循环很常见,可以专门写一个函数。
for(i = 0; i < len2/2; i++){
temp = b[i];
b[i] = b[len2-1-i];
b[len2-1-i] = temp;
}
for(i = 0; i < len1 && i < len2; i++){
M = (a[i] - '0' + b[i] - '0' + L) % 10;
L = (a[i] - '0' + b[i] - '0' + L) / 10;
c[i] = M + '0';
}//M是代表这一位的数,L是代表这一位两数相加后的十位数,也就是进位数的大小
if(i < len1){
for( ; i < len1; i++){
M = (a[i] - '0' + L) % 10;
L = (a[i] - '0' + L) / 10;
c[i] = M + '0';
}
}
if(i < len2){
for( ; i < len2; i++){
M = (b[i] - '0' + L) % 10;
L = (b[i] - '0' + L) / 10;
c[i] = M + '0';
}
}
while(L){
c[i++] = L + '0';
L /= 10;
}//最后一位的进位不要忘记
mark = i-1;
}
int len;char num1[188080],num2[188000],a[180000],sum[188000],sum2[188000];
int js(int q)
{
for(int i=0;i<=q;i++)
{
//printf("a[%d]=%d a[%d]=%d\n",i,a[i],q,a[i+q]);
if(a[i]>a[i+q]) return 0;
else if(a[i]strlen(b)) return 1;
else if(strlen(a)=0;i--)
{
//printf("a[%d]=%c b[%d]=%c\n",i,a[i],i,b[i]);
if(a[i]>b[i]) return 1;
else if(a[i]=0;i--)
printf("%d",sum[i]);
printf("\n");*/
int n;
scanf("%d",&n);
scanf("%s",a);
int q=n/2,j=0;
//printf("q.1=%d",q)
while(a[q]=='0'&&q=0) q--;
if(q==n/2&&(n%2==1))
{
if(js(q)==1)
{
if(a[q+1]!='0') q++;
}
//printf("q=%d\n",q);
}
for(int i=0;i=0;i--)
printf("%c",sum[i]);
printf("\n");
}
else
{
for(int i=strlen(sum2)-1;i>=0;i--)
printf("%c",sum2[i]);
printf("\n");
}
}