ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215161 | #2656. add | wujiachen | 30 | 10ms | 9044kb | C++ | 2.2kb | 2024-11-26 21:35:47 | 2024-11-26 23:05:34 |
answer
#include<bits/stdc++.h>
using namespace std;
string z[1000005];
string add(string str1,string str2){
string str;
int len1=str1.length();
int len2=str2.length();
if(len1<len2)
{
for(int i=1;i<=len2-len1;i++)
str1="0"+str1;
}
else{
for(int i=1;i<=len1-len2;i++)
str2="0"+str2;
}
len1=str1.length();
int cf=0;
int temp;
for(int i=len1-1;i>=0;i--)
{
temp=str1[i]-'0'+str2[i]-'0'+cf;
cf=temp/10;
temp%=10;
str=char(temp+'0')+str;
}
if(cf!=0) str=char(cf+'0')+str;
return str;
}
int main(){
string s,son1="";
cin>>s;
int n=s.length();
z[0]=s[0];
for(int i=1;i<n;i++){
z[i]=z[i-1]+s[i];
}
for(int j=0;j<=n/3+1;j++){//(i+1,n-1) 0,1,2,3,4,5 6,7,8 9,10,11 (n-1-i/2) j:(n/3+1,0)i:(0,n/3+1)
int i=n/3+1-j;
son1=z[i];
string son2="",son3="";
//cout<<s[i]-'0'<<" "<<s[i+(n-1-i)/2]-'0'<<" "<<s[n-1]-'0'<<endl;
if((s[i]-'0'+s[i+(n-1-i)/2]-'0')%10!=s[n-1]-'0')continue;
son2=s.substr(i+1,(n-1-i)/2);
son3=s.substr(i+1+(n-1-i)/2,n-i+1+(n-1-i)/2+1);
//cout<<son1<<" "<<son2<<" "<<son3<<endl;
if(son3==add(son1,son2)){
cout<<son1<<"+"<<son2<<"="<<son3<<endl;
return 0;
}
}
for(int i=n/3;i<=n/2;i++){//son1:(0 i)lengh=i+1 0 1 2 3 4 5 6 7 8 9 10 11 son3 lengh=i+2
string son1=z[i];
string son2="",son3="";
if((s[i]-'0'+s[n-i-2]-'0')%10!=s[n-1]-'0')continue;
son2=s.substr(i+1,n-i-i-2);
son3=s.substr(n-i-1,i+1);
if(son3==add(son1,son2)){
cout<<son1<<"+"<<son2<<"="<<son3<<endl;
return 0;
}
}
for(int i=n/3;i<=n/2;i++){//son1:(0 i)lengh=i+1 0 1 2 3 4 5 6 7 8 9 10 11 son3 lengh=i+2
string son1=z[i];
string son2="",son3="";
if((s[i]-'0'+s[n-i-3]-'0')%10!=s[n-1]-'0')continue;
son2=s.substr(i+1,n-i-i-3);
son3=s.substr(n-i-2,i+1);
if(son3==add(son1,son2)){
cout<<son1<<"+"<<son2<<"="<<son3<<endl;
return 0;
}
}
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 3ms
memory: 9040kb
input:
93944386991110939443869921
output:
939443869911+10=939443869921
result:
ok single line: '939443869911+10=939443869921'
Test #2:
score: 5
Accepted
time: 0ms
memory: 9040kb
input:
454431423351945476661
output:
45443142+33519=45476661
result:
ok single line: '45443142+33519=45476661'
Test #3:
score: 5
Accepted
time: 0ms
memory: 9040kb
input:
807674775734008076747757340
output:
8076747757340+0=8076747757340
result:
ok single line: '8076747757340+0=8076747757340'
Test #4:
score: 5
Accepted
time: 0ms
memory: 9044kb
input:
47936157175791479437362
output:
479361571+75791=479437362
result:
ok single line: '479361571+75791=479437362'
Test #5:
score: 5
Accepted
time: 4ms
memory: 9040kb
input:
8684160719450790868416071945079
output:
868416071945079+0=868416071945079
result:
ok single line: '868416071945079+0=868416071945079'
Test #6:
score: 5
Accepted
time: 3ms
memory: 9040kb
input:
3150325920082064131504079841
output:
31503259200+820641=31504079841
result:
ok single line: '31503259200+820641=31504079841'
Test #7:
score: 0
Memory Limit Exceeded
input:
9261598869160335057970310229283612818845075445997339978957735823966059362624832990688056822195031820...
output:
result:
Test #8:
score: 0
Memory Limit Exceeded
input:
4701609646464966471786112512122938863110668626139644802941307402470417596440427343650542031038908331...
output:
result:
Test #9:
score: 0
Memory Limit Exceeded
input:
9257202799561473086244723527541134302291247300137775651258683390946286052100443441136004200934466749...
output:
result:
Test #10:
score: 0
Memory Limit Exceeded
input:
4416728326936622856150699213135191910979789931946758505266833530473668185681946524100519868737557117...
output:
result:
Test #11:
score: 0
Memory Limit Exceeded
input:
3061041362133228009344583160193669358685821190644364754039063887060686947993153784177860432362852231...
output:
result:
Test #12:
score: 0
Memory Limit Exceeded
input:
8531603642906385747583399978283975747482545589702570907905311483331351132043885935451850547243462360...
output:
result:
Test #13:
score: 0
Memory Limit Exceeded
input:
3334731073815946487356418721839719459473953466541212185094515699104064312397044785650155583747481091...
output:
result:
Test #14:
score: 0
Memory Limit Exceeded
input:
7113181137342253409543193679407457232222929505170124047879622285985297849800487899060254257891240998...
output:
result:
Test #15:
score: 0
Memory Limit Exceeded
input:
2226576415518523623432262365703901892218433052474981493103118406267304359951441730045611163295598279...
output:
result:
Test #16:
score: 0
Memory Limit Exceeded
input:
7282380568017210841065149843225478309106222219195648724985194189592224139941051182898879219925651713...
output:
result:
Test #17:
score: 0
Memory Limit Exceeded
input:
6172023021615818261278406139291452768117320772111777913293782100858187571870407831738505138788606992...
output:
result:
Test #18:
score: 0
Memory Limit Exceeded
input:
1641729471229192950020661455158841378773007409709289573050186474289570718374236969060246403530844480...
output:
result:
Test #19:
score: 0
Memory Limit Exceeded
input:
6878197288916471551222877849454599200431985721720556540869310866854759368074574456390764568703818252...
output:
result:
Test #20:
score: 0
Memory Limit Exceeded
input:
1336335135465815186373041570173603326293570642638147764739718555949768772153761126675803325646928488...