首页 技术 正文
技术 2022年11月15日
0 收藏 479 点赞 4,393 浏览 823 个字

12/25

#include<bits/stdc++.h>
using namespace std;void solve(){
int A,B,coef,exp;
cin>>A>>B;
if(B==1) cout<<A;
else if(B==0) cout<<0;
else{
coef=A*B;exp=B-1;
cout<<coef<<" "<<exp;
}
while(cin>>A>>B){
//1.B==1,only print A
//2.B==0,print 0
//3.B!=1&&B!=0, print coef,exp :coef=A*B,exp=B-1;
if(B==1) cout<<" "<<A;
else if(B==0) cout<<" "<<0;
else{
coef=A*B;exp=B-1;
cout<<" "<<coef<<" "<<exp;
}
}
}int main(){
solve();
return 0;
}

经审查,是题目理解方面出现偏差。

比如,6x,在经过求导之后的coef,exp为6,0。应该全部输出。而-2这类常数项(如果常数项在首部,那就输出0 0,如果不在首部,那就什么也不输出。)

这类题重要的是挖掘题目的隐藏条件。

测试用例

3 4 -5 2 6 1 -2 0

输出样例

1 2 3 -10 1 6 0

测试用例

6 0

输出样例

0 0

测试用例

6 1 6 0

输出样例

6 0

改进后代码

25/25

#include<bits/stdc++.h>
using namespace std;void solve(){
int A,B,coef,exp;
cin>>A>>B;
if(B==1) cout<<A;
else if(B==0) {cout<<0<<" "<<0;return;}
else{
coef=A*B;exp=B-1;
cout<<coef<<" "<<exp;
}
while(cin>>A>>B){
if(B!=0){
coef=A*B;exp=B-1;
cout<<" "<<coef<<" "<<exp;
}
}
}int main(){
solve();
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848