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語言中的棧有關,相關一部分知識,明天這時候我來詳談。