东北大学acm暑期夏令营结构体

2023-11-14

<!doctype html>

NEUQ-ACM-CAMP-B011-结构体-枚举
NEUQ-ACM-CAMP-B011-结构体-枚举
开始时间 2022/08/18 08:07:00
结束时间 2022/08/31 23:59:00
答题时长 19672分钟
答卷类型 标准答案
总分 100

程序填空题 得分:暂无 总分:10
5-1

下列程序读入时间数值,将其加1秒后输出,时间格式为:hh: mm: ss,即“小时:分钟:秒”,当小时等于24小时,置为0。

#include <stdio.h>
struct { 
     int hour, minute, second;
} time;
int main(void)
{  
      scanf("%d:%d:%d", (1分) );
      time.second++;
      if( (1分) == 60){
           (1分) ; 
          time.second = 0;
          if(time.minute == 60){
              time.hour++; 
              time.minute = 0;
              if( (1分)  ) 
                 time.hour = 0; 
          }
      }
      printf ("%d:%d:%d\n", time.hour, time.minute, time.second );
  return 0;

}


5-2

读入一个整型数表示的秒数,将它转换为时分秒格式并输出。

#include <stdio.h>
struct TIME {
    int sec, min, hour;
} time;

int main()
{
int t;

scanf(&quot;%d&quot;, &amp;t);
time.hour = <span data-reactroot=""><input type="text" style="max-width:none;width:19.2ch;max-height:500px" value="t / 3600" disabled=""/><span style="margin-left:4px;color:gray">(2分)</span></span>;
time.min = <span data-reactroot=""><input type="text" style="max-width:none;width:32.4ch;max-height:500px" value="(t - time.hour * 3600) / 60" disabled=""/><span style="margin-left:4px;color:gray">(2分)</span></span>;
time.sec = t % 60;

printf (&quot;<span data-reactroot=""><input type="text" style="max-width:none;width:19.2ch;max-height:500px" value="%02d:%02d:%02d" disabled=""/><span style="margin-left:4px;color:gray">(2分)</span></span>\n&quot;, time.hour, time.min, time.sec);
return 0;

}

输入样例

4508

输出样例

01:15:08

函数题 得分:15 总分:15
6-1
计算两个复数之积
(10分)

本题要求实现一个计算复数之积的简单函数。

函数接口定义:

struct complex multiply(struct complex x, struct complex y);

其中struct complex是复数结构体,其定义如下:

struct complex{
    int real;
    int imag;
};

裁判测试程序样例:

#include <stdio.h>

struct complex{
int real;
int imag;
};

struct complex multiply(struct complex x, struct complex y);

int main()
{
struct complex product, x, y;

scanf(&quot;%d%d%d%d&quot;, &amp;x.real, &amp;x.imag, &amp;y.real, &amp;y.imag);
product = multiply(x, y);
printf(&quot;(%d+%di) * (%d+%di) = %d + %di\n&quot;, 
        x.real, x.imag, y.real, y.imag, product.real, product.imag);

return 0;

}

/* 你的代码将被嵌在这里 */

输入样例:

3 4 5 6

输出样例:

(3+4i) * (5+6i) = -9 + 38i
编译器
GCC
代码
struct complex multiply(struct complex x, struct complex y)
{
    int real, imag;
    real = x.real*y.real - x.imag*y.imag;
    imag = x.imag*y.real + x.real*y.imag;
    struct complex ret={real,imag};
    return ret;
};
评测结果
答案正确 (10 分)
编译器输出
a.c: In function ‘main’:
a.c:14:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &x.real, &x.imag, &y.real, &y.imag);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 5 2.00 ms 188 KB
1 答案正确 3 2.00 ms 372 KB
2 答案正确 2 2.00 ms 196 KB

6-2
空间两点间的距离
(5分)

已知空间中两点 A(x1,y1,z1)A(x_1,y_1, z_1)A(x1,y1,z1)B(x2,y2,z2)B(x_2,y_2, z_2)B(x2,y2,z2) 之间的欧氏距离定义为:(x1−x2)2+(y1−y2)2+(z1−z2)2\sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}(x1x2)2+(y1y2)2+(z1z2)2

本题要求实现一个函数,计算平面上两点之间的欧氏距离,平面上点的坐标通过以下结构给出:

struct point {
    double x, y, z;
};

函数接口定义:

//  计算并返回平面上两点 a 和 b 之间的欧氏距离
double distance(struct point a, struct point b);

裁判测试程序样例:

#include <stdio.h>
#include <math.h>

struct point {
double x, y, z;
};

void read_point(struct point *p);
double distance(struct point a, struct point b);

int main(void)
{
struct point p1, p2;

read_point(&amp;p1);
read_point(&amp;p2);

printf(&quot;%f\n&quot;, distance(p1, p2));

return 0;

}

void read_point(struct point *p)
{
scanf("%lf %lf %lf", &p->x, &p->y, &p->z);
}

/* 请在这里填写答案 */

输入样例:

在这里给出一组输入。例如:

0 0 0 3 0 4

输出样例:

在这里给出相应的输出。例如:

5.000000
编译器
GCC
代码
//  计算并返回平面上两点 a 和 b 之间的欧氏距离
double distance(struct point a, struct point b)
{
    double dis;
    dis = sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2)+pow(a.z-b.z,2));
    return dis;
}
评测结果
答案正确 (5 分)
编译器输出
a.c: In function ‘read_point’:
a.c:25:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lf %lf %lf", &p->x, &p->y, &p->z);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
测试点得分
测试点 结果 得分 耗时 内存
sample1 答案正确 3 2.00 ms 188 KB
sample2 答案正确 2 2.00 ms 328 KB

编程题 得分:75 总分:75
7-1
复数运算
(5分)

复数是由两个实数分别作为实部和虚部构成的一个复合数,从另一个角度来说复数就是由两个实数构成的有序对,在C语言中适合用结构类型来表示复数。现在要求用结构类型

typedef struct
{
    float x;
    float y;
} Comp;

及其变量来表示与存储复数,编写程序实现复数的加减法运算。

输入格式:

在一行输入四个用空格分开的实数a1 b1 a2 b2分别表示复数c1 = a1 + b1ic2 = a2 + b2i

输出格式:

复数的输出应符合数学上关于复数的表示习惯:实部与虚部都为零时只输出一个0.00; 有一个为零时,只输出非零的部分; 虚部为负时,例如3-4i,应输出为3.00-4.00i的形式,不要输出为3.00+-4.00i。实部与虚部均保留2位小数,例如3.00-4.00i
输出在两行进行,第一行输出求和的结果,第二行输出求差的结果。

输入样例:

5.00 4.00 3.00 2.00

输出样例:

8.00+6.00i
2.00+2.00i
编译器
GCC
代码
#include<stdio.h>
#include<math.h>
typedef struct
{
    float x;
    float y;
} Comp;

Comp add(Comp x, Comp y);
Comp sub(Comp x, Comp y);
Comp multiply(Comp x, Comp y);
void print(Comp x);

int main()
{
float a1,b1,a2,b2;
scanf("%f%f%f%f",&a1,&b1,&a2,&b2);

Comp x,y;
x.x=a1, x.y=b1;
y.x=a2, y.y=b2;

Comp a = add(x,y);
Comp b = sub(x,y);

print(a);
printf(&quot;\n&quot;);
print(b);


return 0;

}

Comp multiply(Comp x, Comp y)
{
float real, imag;
real = x.xy.x - x.yy.y;
imag = x.yy.x + x.xy.y;
Comp ret={real,imag};
return ret;
};

Comp add(Comp x, Comp y)
{
float real, imag;
real = x.x+y.x;
imag = x.y+y.y;
Comp ret;
ret.x=real,ret.y = imag;
return ret;
};

Comp sub(Comp x, Comp y)
{
float real, imag;
real = x.x-y.x;
imag = x.y-y.y;
Comp ret;
ret.x=real,ret.y = imag;
return ret;
};

void print(Comp x)
{
if (x.x0 && x.y0)
printf(“0.00”);
else if(x.y==0)
printf(“%.2f”,x.x);
else if(x.x == 0)
printf(“%.2fi”,x.y);
else if(x.y>0)
printf(“%.2f+%.2fi”,x.x,x.y);
else
printf(“%.2f%.2fi”,x.x,x.y);
}

评测结果
答案正确 (5 分)
编译器输出
a.c: In function ‘main’:
a.c:19:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf(“%f%f%f%f”,&a1,&b1,&a2,&b2);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
测试点得分
测试点 结果 得分 耗时 内存
1 答案正确 2 2.00 ms 320 KB
2 答案正确 1 2.00 ms 188 KB
3 答案正确 1 2.00 ms 184 KB
4 答案正确 1 2.00 ms 188 KB

7-2
结构体应用:计算总分及最高分
(10分)

本题目要求先输入正整数N,然后输入N个类型为结构体stud的数组元素,计算每个学生的总分,输出每个学生的学号、姓名、三门课的成绩及总分;计算全部成绩的平均分并输出;输出总分最高同学的各项信息。
struct stud {
int num; //学号
char name[10]; //姓名
int score[3]; //3门课成绩
int sum; //总分
};

输入格式:

先输入不超过10的一个正整数N,然后每行输入一个学生的信息(学号、姓名、三门课成绩)。学号在整数范围内,姓名长度小于10个字符。

输出格式:

首先输出每个学生的信息(包括学号、姓名、三门课成绩、总分),数据项之间空1格,每人一行;再输出全部成绩的平均分;最后输出总分最高(假设没有相同总分)同学的学号、姓名、三门课成绩及总分,数据项之间空1格。

输入样例:

在这里给出一组输入。例如:

4
1  张三  81  85  82
2  李四  82  78  74
3  王五  85  74  90
4  赵六  77  85  79

输出样例:

在这里给出相应的输出。例如:

1 张三 81 85 82 248
2 李四 82 78 74 234
3 王五 85 74 90 249
4 赵六 77 85 79 241
总平均分=81.000000
3 王五 85 74 90 249
编译器
GXX
代码
#include <bits/stdc++.h>
using namespace std;
struct stud
{
    int num; //学号
    char name[10]; //姓名
    int score[3]; //3门课成绩
    int sum; //总分
};

int main()
{
int n;
cin>>n;

stud st[n];
int max=-1, pos=-1,sum=0;
for(int i=0;i&lt;n; i++)
{
    cin&gt;&gt;st[i].num;
    cin&gt;&gt;st[i].name;
    cin&gt;&gt;st[i].score[0]&gt;&gt;st[i].score[1]&gt;&gt;st[i].score[2];
    st[i].sum=st[i].score[0]+st[i].score[1]+st[i].score[2];
    if (max &lt; st[i].sum)
    {
        max = st[i].sum;
        pos = i;
    }
    sum += st[i].sum;
}

 for(int i=0;i&lt;n; i++)
 {
     cout&lt;&lt;st[i].num&lt;&lt;&#x27; &#x27;&lt;&lt;st[i].name&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].score[0]&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].score[1]&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].score[2]&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].sum&lt;&lt;endl;
 }
double avg = (double)sum / (n*3.0);
cout&lt;&lt;&quot;总平均分=&quot;;
printf(&quot;%.6f\n&quot;,avg);

int i=pos;
cout&lt;&lt;st[i].num&lt;&lt;&#x27; &#x27;&lt;&lt;st[i].name&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].score[0]&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].score[1]&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].score[2]&lt;&lt;&#x27; &#x27;
         &lt;&lt;st[i].sum&lt;&lt;endl;

return 0;

}

评测结果
答案正确 (10 分)
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 5 3.00 ms 448 KB
1 答案正确 3 3.00 ms 444 KB
2 答案正确 2 3.00 ms 448 KB

7-3
2021-结构体-circle
(5分)

定义一个结构体类型表示一个圆(x,y,r),圆心坐标是(x,y),圆半径是r。从键盘输入一个圆的圆心坐标和半径,坐标值和半径均为整型数据,输出这个圆的面积,面积为float。面积公式为area=3.14∗r∗rarea =3.14rrarea=3.14rr.

输入格式:

从键盘输入圆的圆心坐标和半径,之间用空格分隔

输出格式:

输出数据保留两位小数。

输入样例:

在这里给出一组输入。例如:

3 4 5

输出样例:

在这里给出相应的输出。例如:

78.50
编译器
GXX
代码
#include <bits/stdc++.h>
using namespace std;
struct Circle
{
    int x,y,r;
    float GetArea()
    {
        return (float) 3.14 * r * r;
    }
};

int main()
{
Circle c1;
cin>>c1.x>>c1.y>>c1.r;

cout&lt;&lt;fixed&lt;&lt;setprecision(2)&lt;&lt; c1.GetArea();


return 0;

}

评测结果
答案正确 (5 分)
测试点得分
测试点 结果 得分 耗时 内存
1 答案正确 5 3.00 ms 444 KB

7-4
寻找最高分
(5分)

  给定n(n⩾1)n(n\geqslant1)n(n1)个学生的学号、姓名和3门课的考试成绩。编写程序找出总分最高的学生,并输出其学号、姓名和总分。如果有多个相同的最高分,则输出所有最高分学生的信息。
要求:
  存储学生信息及考试成绩的变量用如下结构类型来定义。

struct  Student
{
    char num[11];        //学号,最多10个字符
    char name[11];       //姓名, 最多10个字符
    int s1,s2,s3;        //三门课的考试成绩 
    int total;           //总成绩   
} ;
typedef struct Student Student;  //声明了一个结构类型Student类型

输入格式:

输入在一行中给出非负整数n(n⩾1)n(n\geqslant1)n(n1)。随后nnn行,每行给出一个学生的信息,格式为学号 学号 姓名 成绩1 成绩2 成绩3,中间以空格分隔。
要求:
学号姓名中不包括空白字符(空格、tab符)和空字符串。

输出格式:

在一行中输出总分最高学生的姓名、学号和总分,间隔一个空格。题目保证这样的学生是唯一的。

输入样例:

5
2109001 HuangJie 78 83 79
2109002 Liuhaipeng 79 80 77
2109003 Wangqiang 87 86 76
2109004 Liangfeng 92 89 79
2109005 Chengmeng 80 82 75

输出样例:

在这里给出相应的输出。例如:

2109004 Liangfeng 260
编译器
GXX
代码
#include <bits/stdc++.h>
using namespace std;

struct Student
{
string num; //学号,最多10个字符
string name; //姓名, 最多10个字符
int s1,s2,s3; //三门课的考试成绩
int total; //总成绩
bool operator < (const Student &s) const
{
return total < s.total;
}
} ;

int main()
{
int n;
cin>>n;

priority_queue&lt;Student&gt; Q;
for(int i=0; i&lt;n; i++)
{
    Student st;
    cin&gt;&gt;st.num&gt;&gt;st.name&gt;&gt;st.s1&gt;&gt;st.s2&gt;&gt;st.s3;
    st.total = st.s1+st.s2+st.s3;
    Q.push(st);
}

Student st;
int flag;
st = Q.top();
Q.pop();
flag = st.total;
cout&lt;&lt;st.num&lt;&lt;&#x27; &#x27;&lt;&lt;st.name&lt;&lt;&#x27; &#x27;&lt;&lt;st.total&lt;&lt;&#x27;\n&#x27;;

while (!Q.empty())
{
    st = Q.top();
    Q.pop();
    if (st.total == flag)
        cout&lt;&lt;st.num&lt;&lt;&#x27; &#x27;&lt;&lt;st.name&lt;&lt;&#x27; &#x27;&lt;&lt;st.total&lt;&lt;endl;
    else break;
}


return 0;

}

评测结果
答案正确 (5 分)
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 3 3.00 ms 324 KB
1 答案正确 1 3.00 ms 324 KB
2 答案正确 1 3.00 ms 320 KB

7-5
平面向量加法
(10分)

本题要求编写程序,计算两个二维平面向量的和向量。

输入格式:

输入在一行中按照“x1x_1x1 y1y_1y1 x2x_2x2 y2y_2y2”的格式给出两个二维平面向量v1=(x1,y1)v_1=(x_1, y_1)v1=(x1,y1)v2=(x2,y2)v_2=(x_2, y_2)v2=(x2,y2)的分量。

输出格式:

在一行中按照(x, y)的格式输出和向量,坐标输出小数点后一位(注意不能输出−0.0-0.00.0)。

输入样例:

3.5 -2.7 -13.9 8.7

输出样例:

(-10.4, 6.0)
编译器
GXX
代码
#include<bits/stdc++.h>
using namespace std;

struct V
{
double x,y;
};

int main()
{
V v1,v2,v;
cin>>v1.x>>v1.y;
cin>>v2.x>>v2.y;
v.x = v1.x + v2.x;
v.y = v1.y + v2.y;

if(fabs(v.y)&lt;0.05) v.y=0;
if(fabs(v.x)&lt;0.05) v.x=0;
printf(&quot;(%.1lf, %.1lf)\n&quot;,v.x,v.y);

return 0;    

}

评测结果
答案正确 (10 分)
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 5 3.00 ms 452 KB
1 答案正确 5 3.00 ms 452 KB

7-6
有理数比较
(10分)

本题要求编写程序,比较两个有理数的大小。

输入格式:

输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整形范围内的正整数。

输出格式:

在一行中按照“a1/b1 关系符 a2/b2”的格式输出两个有理数的关系。其中“>>>”表示“大于”,“<<<”表示“小于”,“===”表示“等于”。

输入样例1:

1/2 3/4

输出样例1:

1/2 < 3/4

输入样例2:

6/8 3/4

输出样例2:

6/8 = 3/4
编译器
GXX
代码
#include <bits/stdc++.h>
using namespace std;
struct fraction
{
    int sign;
    int fz;
    int fm;
};

fraction add(const fraction &a, const fraction &b)
{
fraction ans;
if (a.sign == b.sign)
{
ans.sign = a.sign;
ans.fz = a.fzb.fm+a.fmb.fz;
ans.fm = a.fm * b.fm;
}
else
{
ans.fz = a.sign * a.fzb.fm + a.fmb.signb.fz;
ans.fm = a.fm
b.fm;
if (ans.fz <0) ans.sign = -1;
else ans.sign = 1;
}
int gcd = __gcd(ans.fz,ans.fm);
ans.fz = ans.fz / gcd;
ans.fm = ans.fm / gcd;

return ans;

}

fraction sub(const fraction &a, const fraction &b)
{
fraction c = b;
c.sign = -c.sign;
return add(a,c);
}

void print(const fraction &f)
{
if (f.fm == 1) cout<<f.signf.fz;
else
cout<<f.sign
f.fz<<'/'<<f.fm;
}

fraction read()
{
int z,m;
char slash;
fraction temp= {1,0,1};

cin&gt;&gt;z&gt;&gt;slash&gt;&gt;m;
temp.sign = (z&gt;=0)?1:-1;
temp.fz = temp.sign *z;
temp.fm = m;

return temp;    

}

char fraction_compare(fraction &a,fraction &b)
{
fraction res = sub(a,b);

if (res.sign ==1 &amp;&amp; res.fz&gt;0)
    return &#x27;&gt;&#x27;;
else if(res.fz == 0)
    return &#x27;=&#x27;;
else return &#x27;&lt;&#x27;;    

}

int main()
{
fraction a=read();
fraction b=read();
fraction res = sub(a,b);
print(a);
cout<<’ ‘<<fraction_compare(a,b)<<’ ';
print(b);
return 0;
}

评测结果
答案正确 (10 分)
编译器输出
a.cpp: In function ‘int main()’:
a.cpp:76:14: warning: variable ‘res’ set but not used [-Wunused-but-set-variable]
fraction res = sub(a,b);
^~~
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 3 3.00 ms 324 KB
1 答案正确 3 3.00 ms 324 KB
2 答案正确 2 3.00 ms 308 KB
3 答案正确 2 3.00 ms 448 KB

7-7
有理数加法
(10分)

本题要求编写程序,计算两个有理数的和。

输入格式:

输入在一行中按照a1/b1 a2/b2的格式给出两个分数形式的有理数,其中分子和分母全是整形范围内的正整数。

输出格式:

在一行中按照a/b的格式输出两个有理数的和。注意必须是该有理数的最简分数形式,若分母为1,则只输出分子。

输入样例1:

1/3 1/6

输出样例1:

1/2

输入样例2:

4/3 2/3

输出样例2:

2
编译器
GXX
代码
#include <bits/stdc++.h>
using namespace std;
struct fraction
{
    int sign;
    int fz;
    int fm;    
};

fraction add(const fraction &a, const fraction &b)
{
fraction ans;
if (a.sign == b.sign)
{
ans.sign = a.sign;
ans.fz = a.fzb.fm+a.fmb.fz;
ans.fm = a.fm * b.fm;
}
else
{
ans.fz = a.sign * a.fzb.fm + a.fmb.signb.fz;
ans.fm = a.fm
b.fm;
(ans.fz <0)? (ans.sign = -1,ans.fz=-ans.fz):(ans.sign=1);

}
int gcd = __gcd(ans.fz,ans.fm);
ans.fz = ans.fz / gcd;
ans.fm = ans.fm / gcd;   

return ans;    

}

void print(const fraction &f)
{
if (f.fm == 1) cout<<f.signf.fz;
else
cout<<f.sign
f.fz<<'/'<<f.fm;
}

int main()
{
int n=2;
//cin>>n;

fraction res={1,0,1};
int z,m;
char slash;
fraction temp={1,0,1};
for(int i=1; i&lt;=n; i++)
{
    cin&gt;&gt;z&gt;&gt;slash&gt;&gt;m;
    temp.sign = (z&gt;=0)?1:-1;
    temp.fz = temp.sign *z;
    temp.fm = m;
    
    res = add(res,temp);        
}

//res.fm = res.fm *n;

int gcd = __gcd(res.fz,res.fm);
res.fz = res.fz / gcd;
res.fm = res.fm / gcd;   

print(res);

return 0;

}

评测结果
答案正确 (10 分)
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 3 3.00 ms 324 KB
1 答案正确 3 2.00 ms 328 KB
2 答案正确 3 3.00 ms 444 KB
3 答案正确 1 2.00 ms 320 KB

7-8
有理数均值
(10分)

本题要求编写程序,计算N个有理数的平均值。

输入格式:

输入第一行给出正整数N(≤\le100);第二行中按照a1/b1 a2/b2 …的格式给出N个分数形式的有理数,其中分子和分母全是整形范围内的整数;如果是负数,则负号一定出现在最前面。

输出格式:

在一行中按照a/b的格式输出N个有理数的平均值。注意必须是该有理数的最简分数形式,若分母为1,则只输出分子。

输入样例1:

4
1/2 1/6 3/6 -5/10

输出样例1:

1/6

输入样例2:

2
4/3 2/3

输出样例2:

1
编译器
GXX
代码
#include <bits/stdc++.h>
using namespace std;
struct fraction
{
    int sign;
    int fz;
    int fm;    
};

fraction add(const fraction &a, const fraction &b)
{
fraction ans;
if (a.sign == b.sign)
{
ans.sign = a.sign;
ans.fz = a.fzb.fm+a.fmb.fz;
ans.fm = a.fm * b.fm;
}
else
{
ans.fz = a.sign * a.fzb.fm + a.fmb.signb.fz;
ans.fm = a.fm
b.fm;
ans.fz < 0 ? ans.sign = -1, ans.fz=-ans.fz: ans.sign=1;

}
int gcd = __gcd(ans.fz,ans.fm);
ans.fz = ans.fz / gcd;
ans.fm = ans.fm / gcd;   

return ans;    

}

void print(const fraction &f)
{
if (f.fm == 1) cout<<f.signf.fz;
else
cout<<f.sign
f.fz<<'/'<<f.fm;
}

int main()
{
int n;
cin>>n;

fraction res={1,0,1};
int z,m;
char slash;
fraction temp={1,0,1};
for(int i=1; i&lt;=n; i++)
{
    cin&gt;&gt;z&gt;&gt;slash&gt;&gt;m;
    temp.sign = (z&gt;=0)?1:-1;
    temp.fz = temp.sign *z;
    temp.fm = m;
    
    res = add(res,temp);        
}

res.fm = res.fm *n;

int gcd = __gcd(res.fz,res.fm);
res.fz = res.fz / gcd;
res.fm = res.fm / gcd;   

print(res);

return 0;

}

评测结果
答案正确 (10 分)
测试点得分
测试点 结果 得分 耗时 内存
0 答案正确 4 3.00 ms 448 KB
1 答案正确 2 3.00 ms 448 KB
2 答案正确 2 3.00 ms 444 KB
3 答案正确 2 3.00 ms 436 KB

7-9
排列枚举
(10分)

口袋里有红、蓝、黄、黑4种颜色的球若干,每次从口袋先后取出3个球,问得到3种不同颜色的球的可能取法,输出每种排列的情况。球只能是4种颜色之一,而且判断各球是否同色,可以用枚举类型变量处理。

输入格式:

输出格式:

输出所有排列。

输入样例:

在这里给出一组输入。例如:

输出样例:

在这里给出相应的输出。例如:

1 red blue yellow
2 red blue black
3 red yellow blue
4 red yellow black
5 red black blue
6 red black yellow
7 blue red yellow
8 blue red black
9 blue yellow red
10 blue yellow black
11 blue black red
12 blue black yellow
13 yellow red blue
14 yellow red black
15 yellow blue red
16 yellow blue black
17 yellow black red
18 yellow black blue
19 black red blue
20 black red yellow
21 black blue red
22 black blue yellow
23 black yellow red
24 black yellow blue
编译器
GXX
代码
#include <bits/stdc++.h>

using namespace std;

enum color{red,blue,yellow,black};
string color_arr[4]={"red","blue","yellow","black"};

int main()
{
int cnt = 0;
for(int i=red;i<=black;i++)
{
for(int j = red;j<=black;j++)
{
for(int k = red;k<=black;k++)
{
if(i!=j&&j!=k&&i!=k)
{
cnt++;
cout<<cnt<<" "<<color_arr[i]<<" "<<color_arr[j]<<" "<<color_arr[k]<<endl;
}
}
}
}

return 0;

}

评测结果
答案正确 (10 分)
测试点得分
测试点 结果 得分 耗时 内存
1 答案正确 10 3.00 ms 440 KB

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

东北大学acm暑期夏令营结构体 的相关文章

随机推荐

  • R语言之 as.formula()

    今天学到一个东西 R 语言回归函数里面的公式函数 as formula 其作用就是将字符串转换成公式 gt aa ReadCount Age BMI Sex HAMD 1 1 Sex gt aa 1 ReadCount Age BMI Se
  • MFC之滑块与旋转控件23

    1 滑块 首先看看滑块相关的内容 从sitch看到 滑块分为五个内容 分别是矩形滑块位置 滑块左右两边的箭头 和矩形滑块分别距离左右两边的空间 1 先添加滑块控件和显示矩形滑块的位置编辑区 2 右击编辑区添加变量为int类型 3 添加滑块为
  • Qt实现不同项目的信号传递

    Qt实现windows通信 不同项目的窗口通信 有关Qt通信的知识 windows要实现不同项目窗口通信 需要用类似于windows h的api接口 数据传输主要通过 typedef struct tagCOPYDATASTRUCT cds
  • nowcoder-15165-字符串问题-kmp

    题目描述 有一个字符串 让你找到这个字符串 S 里面的子串T 这个子串 T 必须满足即使这个串的前缀 也是这个 串的后缀 并且 在字符串中也出现过一次的 提示 要求满足前后缀的同时也要在字符串中出现一次 只是前后缀可不行 输出最长满足要求字
  • Shell脚本进阶版合集

    文章目录 一 Linux监控服务端口脚本 二 Linux编译安装Nginx脚本 三 Linux监控一个主机状态脚本 四 Linux统计内存 CPU使用前十进程脚本 五 Linux 磁盘I O列长度监控脚本 六 Linux计算内存使用率占比
  • 【多元统计分析】09.独立性检验与正态性检验

    文章目录 九 独立性检验和正态性检验 1 独立性检验 2 一元数据正态性检验 3 多元数据的正态性检验 回顾总结 九 独立性检验和正态性检验 1 独立性检验 独立性检验 指的是将一个多元总体 X N p
  • 【cmake】find_package设置查找路径

    1 find package的作用与实例 用来查找第三方依赖包的 cmake文件 并根据 cmake文件生成依赖包的头文件目录和库文件路径等 CMakeLists txt实例 find package Protobuf REQUIRED i
  • [大话设计模式C++版] 第14章 老板回来,我不知道 —— 观察者模式

    源码可以在这里找到 大话设计模式C 版 双向耦合的代码 Secretary h 秘书类 include
  • numpy对array索引

    numpy中array索引 对numpy的array索引时总是容易出错 借此机会总结一下numpy中array最常用的索引方法 1 单个元素的索引 In 1 1 1 一维array 单个元素的索引使用整数 import numpy as n
  • 能把百度玩出花样的人肯定不简单,分享几个鲜为人知的搜索引擎高级语法

    作者主页 士别三日wyx 作者简介 CSDN top100 阿里云博客专家 华为云享专家 网络安全领域优质创作者 专栏简介 此文章已录入专栏 网络安全快速入门 渗透过程中 通常会使用搜索引擎来收集重要信息 确定攻击点 Google 黑客语法
  • 牛客题集——Cook Steak(警示 理解题意)

    Cook Steak 题目链接 题目译文 对于烤牛排 ZJH认为它需要N道烧烤工序 每道工序都在一个温度范围内 li ri 就一分钟而言 只有在这种情况下 烤牛排才是最好的 幸运的是 厨房里的设备已经配备了人工智能 可以在最短的时间内快速完
  • 浏览器缓存的位置

    缓存位置的类型 缓存位置有四种 各自有优先级 当依次查找缓存且都没有命中的时候 才会去请求网络 Service Worker Memory Cache Disk Cache Push Cache Service Worker Service
  • Web基础(从零开始)——HTML下拉菜单 select标签详解

  • 设计模式【15】——状态模式(State模式)

    文章目录 前言 一 状态模式 State模式 二 具体源码 1 State h 2 State cpp 3 Context h 4 Context cpp 5 main cpp 三 运行结果 总结 前言 每个人 事物在不同的状态下会有不同表
  • mysql实训总结日记_常用SQL语句总结-MySQL 学习日记

    写在前面 下面主要总结的是SQL的数据类型和DDL DML和DCL的基础用法 适合查阅 纯结构化文本读起来需要耐心 勤于练习 勤于练习 勤于练习 2018 05 30第一次修改 SQL Structured Query Language结构
  • 小程序跟服务器长连接,h5和小程序socket长连接和公共管理方案(vue+redux+websocket)...

    h5和小程序socket长连接和公共管理方案 vue redux websocket h5和小程序socket长连接和公共管理方案 vue redux websocket socket和公共状态管理连接方案 vuex redux和小程序 w
  • 【云原生之kubernetes】kubernetes集群下Secret存储对象的管理

    云原生之kubernetes kubernetes集群下Secret存储对象的管理 一 Secret存储对象介绍 1 Secret简介 2 Secret的类型 二 检查本地kubernetes集群状态 1 检查工作节点 2 检查系统pod节
  • Linux下动态链接库的使用

    1 所谓链接 也就是说编译器找到程序中所引用的函数或全局变量所存在的位置 一般来说 程序的链接分为静态链接和动态链接 静态链接就是把所有所引用到的函数或变量全部地编译到可执行文件中 动态链接则不会把函数编译到可执行文件中 而是在程序运行时动
  • 固态硬盘Ghost安装Windows 10无法引导的问题

    机器配置如下 电脑型号 技嘉 B360M POWER 台式电脑 操作系统 Windows 10 64位 DirectX 12 处理器 英特尔 Core i7 8700 3 20GHz 六核 主板 技嘉 B360M POWER 英特尔 PCI
  • 东北大学acm暑期夏令营结构体

    NEUQ ACM CAMP B011 结构体 枚举 NEUQ ACM CAMP B011 结构体 枚举 开始时间 2022 08 18 08 07 00 结束时间 2022 08 31 23 59 00 答题时长 19672分钟 答卷类型