Prince0618 @ 2024-10-05 23:52:04
这道题让我知道了一件事。
那就是洛谷的难度都是假的。
看看我的代码:
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
int count(int a){
int ans=0;
if(a==0) return ans+1;
while(a!=0){
a/=10;
ans+=1;
}
return ans;
}
int main(){
int i,a,b;
char c;
cin>>i;
for(int j=0;j<i;j++){
cin>>c;
if(c>='a'&&c<='c') cin>>a>>b;
if(c!='a'&&c!='b'&&c!='c'){
cin>>a>>b;
a+=(c-'0')*(10^count(a));
cout<<a<<"+"<<b<<"="<<a+b<<endl;
cout<<2+count(a)+count(b)+count(a+b)<<endl;
}
if(c=='a'){
cout<<a<<"+"<<b<<"="<<a+b<<endl;
cout<<2+count(a)+count(b)+count(a+b)<<endl;
}
else if(c=='b'){
cout<<a<<"-"<<b<<"="<<a-b<<endl;
if(a-b<0) cout<<3+count(a)+count(b)+count(a-b)<<endl;
else cout<<2+count(a)+count(b)+count(a-b)<<endl;
}
else if(c=='c'){
cout<<a<<"*"<<b<<"="<<a*b<<endl;
cout<<2+count(a)+count(b)+count(a*b)<<endl;
}
}
return 0;
}
by Prince0618 @ 2024-10-05 23:53:58
第36行偏了,不用管。
by liuhaoyan0323 @ 2024-10-06 02:25:01
@Prince0618
还好吧就是纯模拟,你是直接读入的时候做,有点麻烦,代码帮你改好了,主要在于前导零+题意理解
的问题,代码如下:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,a,b;
char c,tmp;
bool bl;
inline int read(int &num){
int x=0,f=1,cnt=0;
char ch=getchar();
while(ch>'9'||ch<'0'){
f=(ch=='-')?-1:1;
ch=getchar();
}
while(ch=='0'){
++cnt;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
num=x*f;
return cnt;
}
inline int fpow(int a,int b){
int ans=1;
while(b){
if(b&1)ans*=a;
b>>=1;
a*=a;
}
return ans;
}
inline int count(int a){
int ans=0;
if(a==0) return ans+1;
while(a!=0){
a/=10;
ans+=1;
}
return ans;
}
inline void solve(char c){
if(c=='a'){
printf("%lld+%lld=%lld\n",a,b,a+b);
printf("%lld\n",2+count(a)+count(b)+count(a+b));
}else if(c=='b'){
printf("%lld-%lld=%lld\n",a,b,a-b);
if(a-b<0){
printf("%lld\n",3+count(a)+count(b)+count(a-b));
}else{
printf("%lld\n",2+count(a)+count(b)+count(a-b));
}
}else if(c=='c'){
printf("%lld*%lld=%lld\n",a,b,a*b);
printf("%lld\n",2+count(a)+count(b)+count(a*b));
}
}
signed main(){
read(T);
while(T--){
bl=true;
c=getchar();
if(c>='a'&&c<='c'){
read(a);
read(b);
tmp=c;
}
if(c!='a'&&c!='b'&&c!='c'){
int x=read(a);
read(b);
a+=(c-'0')*fpow(10,count(a)+x);
solve(tmp);
}else{
solve(c);
}
}
return 0;
}
by liuhaoyan0323 @ 2024-10-06 02:26:06
@Prince0618
求关注。
by Prince0618 @ 2024-10-09 21:26:45
@liuhaoyan0323 好的,谢谢dalao. 已关注。
by Prince0618 @ 2024-10-09 21:27:49
@liuhaoyan0323 求关注(没粉丝的555...)