# 洛谷P1957口算练习题题解

### 正文开始：

_话说 ，就当本蒟蒻正高高兴兴的刷水题时，居然
碰到了这个laji题_

### 思路部分：

4

a 64 46

275 125 //这里咋就没有字母了呢？？？？

c 11 99

b 46 64

#### 2.其他办法：

cin>>y;
if(y>='a'&&y<='c'){
w=y;
cin>>s1;
}
cin>>s2;

y=‘2’;

s2=75;

s3=125;

char y;long long s1,s2;
cin>>y>>s1>>s2;
s1=(y-'0')*pow(10,line(s1))+s1;
cout<<s1;
return 0;

long long line(long long i){

long long j=0,k=i;
if(i<=0){
k=-k;
j++;
}

while(k>0){
k=k/10;
j++;
}
return j;
}

## 可是，你难道没发现什么bug：当如测试点2的5002时会：变为52！！！！！！！

### 然后与y一拼，一起化为数字：

cin>>e;
e=y+e;
int le=e.size();int kw=1;int ss=0;
for(int i=le-1;i>=0;i--){
ss+=(kw*(e[i]-'0'));
kw=kw*10;
}
s1=ss;

int main(){
long long n;  cin>>n;
for(long long i=1;i<=n;++i){
getzf();
//cout<<"s1:"<<s1<<" "<<s2<<endl;
if(w=='a'){
cout<<s1<<"+"<<s2<<"="<<s1+s2<<endl;
cout<<line(s1)+2+line(s2)+line(s1+s2)<<endl;
}
else if(w=='b'){
cout<<s1<<"-"<<s2<<"="<<s1-s2<<endl;
cout<<line(s1)+2+line(s2)+line(s1-s2)<<endl;
//cout<<"line:"<<line(s1)<<" "<<line(s2)<<" "<<line(s1-s2)<<endl;
}
else if(w=='c'){
cout<<s1<<"*"<<s2<<"="<<s1*s2<<endl;
cout<<line(s1)+2+line(s2)+line(s1*s2)<<endl;
}
}
return 0;
}

code，完整代码：

#include<bits/stdc++.h>
using namespace std;
string a,e; long long s1,s2;char w,y;//////////////////////iephyhoyhjyeohyohytuohyoihj/////iihjn
long long line(long long i){

long long j=0,k=i;
if(i<=0){
k=-k;
j++;
}

while(k>0){
k=k/10;
j++;
}
return j;
}
void getzf(){
cin>>y;
//cout<<"y:"<<y<<endl;
if(y>='a'&&y<='c'){
w=y;
cin>>s1;
}
else{
cin>>e;
e=y+e;
int le=e.size();int kw=1;int ss=0;
for(int i=le-1;i>=0;i--){
ss+=(kw*(e[i]-'0'));
kw=kw*10;
}
s1=ss;
}
cin>>s2;
//cout<<"s1:"<<s1<<"s2:"<<s2<<endl;
}
int main(){
long long n;  cin>>n;
for(long long i=1;i<=n;++i){
getzf();
//cout<<"s1:"<<s1<<" "<<s2<<endl;
if(w=='a'){
cout<<s1<<"+"<<s2<<"="<<s1+s2<<endl;
cout<<line(s1)+2+line(s2)+line(s1+s2)<<endl;
}
else if(w=='b'){
cout<<s1<<"-"<<s2<<"="<<s1-s2<<endl;
cout<<line(s1)+2+line(s2)+line(s1-s2)<<endl;
//cout<<"line:"<<line(s1)<<" "<<line(s2)<<" "<<line(s1-s2)<<endl;
}
else if(w=='c'){
cout<<s1<<"*"<<s2<<"="<<s1*s2<<endl;
cout<<line(s1)+2+line(s2)+line(s1*s2)<<endl;
}
}
return 0;
}

1.函数化编程！！！！方便调试，方便理解

2.注意细节，避免爆零！！！

byebye~~~~！