# 要在main函数之外定义数组

main函数之外定义数组：

#include<stdio.h>
#include<stdlib.h>

struct Poly
{
int exp;
double coe;
}Poly[1001];//第一个数组

double ans[2001];//外部定义数组

int main()
{
int n;
scanf_s("%d", &n);
for (int  i = 0; i < n; i++)
{
scanf_s("%d%lf", &Poly[i].exp, &Poly[i].coe);
}

//double ans[2001];//内部定义数组

int m,number = 0;
scanf_s("%d", &m);
for (int i = 0; i < m; i++)
{
int exp;
double coe;
scanf_s("%d%lf", &exp, &coe);

for (int j = 0; j < n; j++)
{
ans[exp + Poly[j].exp] += (coe*Poly[j].coe);
}
}

for (int i = 0; i <=2000 ; i++)
{
if (ans[i] != 0.0) number++;
}

printf("%d", number);
for (int i = 2000; i>=0; i--)
{
if (ans[i] != 0.0)
{
printf(" %d %.1f", i, ans[i]);
}

}

system("pause");

return 0;
}


#include<stdio.h>
#include<stdlib.h>

struct Poly
{
int exp;
double coe;
}Poly[1001];//第一个数组

//double ans[2001];//外部定义数组

int main()
{
int n;
scanf_s("%d", &n);
for (int  i = 0; i < n; i++)
{
scanf_s("%d%lf", &Poly[i].exp, &Poly[i].coe);
}

double ans[2001];//内部定义数组

int m,number = 0;
scanf_s("%d", &m);
for (int i = 0; i < m; i++)
{
int exp;
double coe;
scanf_s("%d%lf", &exp, &coe);

for (int j = 0; j < n; j++)
{
ans[exp + Poly[j].exp] += (coe*Poly[j].coe);
}
}

for (int i = 0; i <=2000 ; i++)
{
if (ans[i] != 0.0) number++;
}

printf("%d", number);
for (int i = 2000; i>=0; i--)
{
if (ans[i] != 0.0)
{
printf(" %d %.1f", i, ans[i]);
}

}

system("pause");

return 0;
}


2 1 2.4 0 3.2
2 2 1.5 1 0.5

3 3 3.6 2 6.0 1 1.6

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

大象重返平原

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
04-20 1720

04-13 295
08-04 2863
05-05 8740
03-23 307
08-19 1831
10-18 1250
05-18 1440
10-10 997