PAT 1010的启发
PAT 启发
2023-09-14 09:13:21 时间
1.先粘上提交可通过的代码
#include <stdio.h>
#define maxSize 1000
int main(){
int result[maxSize][2];//存放求出的结果
int a,b;//代表输入的系数与指数
int i = 0;
int count = 0;
while(scanf("%d %d",&a,&b)!=EOF){
if(b!=0){//如果指数项不等于0
result[i][0] = a*b;
result[i][1] = b-1;
i++;//项数增加
count ++;//表示正常的多项式数目
}
}
int j = 0;
if(count == 0){
printf("0 0\n");
return 0;
}
while(j < i){
if(count > 1){
printf("%d %d ",result[j][0],result[j][1]);
count --;
}
else{
printf("%d %d",result[j][0],result[j][1]);
count --;
}
j++;
}
}
//3 4 -5 2 6 1 0 0
//-2 0 3 4 -5 2 6 1
2.再来谈谈启发
#include <stdio.h>
#define maxSize 1000
int main(){
int result[maxSize][2];//存放求出的结果
int a,b;//代表输入的系数与指数
int i = 0;
int count = 0;
while(scanf("%d %d",&a,&b)!=EOF){
if(b!=0){//如果指数项不等于0
result[i][0] = a*b;
result[i][1] = b-1;
i++;//项数增加
count ++;//表示正常的多项式数目
}
}
int j = 0;
if(count == 0){
printf("0 0\n");
return 0;
}
while(j < i){
if(count > 1){
printf("%d %d ",result[j][0],result[j++][1]);
count --;
}
else{
printf("%d %d",result[j][0],result[j++][1]);
count --;
}
}
}
//3 4 -5 2 6 1 0 0
//-2 0 3 4 -5 2 6 1
跑一下程序可以知道程序2是无法得到正确结果的,为什么呢?因为这和C语言中的栈有关,相关一部分知识,明天这时候我来详谈。
相关文章
- PAT乙级1004 成绩排名
- PAT乙级1003-我要通过
- PAT乙级1002-写出这个数
- PAT乙级题目对应知识点分类梳理
- PAT乙级1019
- PAT 乙级 1009
- PAT乙级——1003
- PAT乙级题库
- pat 520钻石争霸赛
- PAT乙级1009. 说反话(C语言)
- IP 综合实验(rip ospf 单臂 重分发,nat,pat )
- pat乙级1002_PAT甲级
- Pat Walters|2022年AI在药物发现领域的技术进展回顾
- PAT 1002 写出这个数(JAVA / Hash)
- PAT (Top Level) Practice 1017 The Best Peak Shape (35 分) 题解
- 视频:VMware CEO Pat Gelsinger离职感言
- cheLinux系统补丁:让操作更快更安全(linux pat)