阅读程序 · 答案 3,2 · 考点:输入输出、位运算、结构体(struct)
← 整套速查表 NOIP 普及组初赛 全部真题阅读程序写结果:
#include <iostream>
using namespace std;
struct point
{
int x;
int y;
};
int main()
{
int a, b, c;
struct EX
{
int a;
int b;
point c;
} e;
e.a = 1;
e.b = 2;
e.c.x= e.a + e.b;
e.c.y= e.a * e.b;
cout << e.c.x << ',' << e.c.y << endl;
return(0);
}看到 struct 嵌套 → 先理清成员链 e.c.x/y
易把 e.c 当整型;输出漏逗号
考点:结构体嵌套|成员访问链
定义外层结构体 EX,其成员 c 为内层结构体 point。先给 e.a、e.b 赋值,再通过链式访问 e.c.x、e.c.y 计算结果,最后逗号分隔输出。