国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

藍橋杯算法訓練 P1103 結構體指針or 暴力

2019-11-11 01:26:04
字體:
來源:轉載
供稿:網友
  算法訓練 P1103  時間限制:1.0s   內存限制:256.0MB        編程實現兩個復數的運算。設有兩個復數 和 ,則他們的運算公式為:  要求:(1)定義一個結構體類型來描述復數。  (2)復數之間的加法、減法、乘法和除法分別用不用的函數來實現。  (3)必須使用結構體指針的方法把函數的計算結果返回。  說明:用戶輸入:運算符號(+,-,*,/) a b c d.  輸出:a+bi,輸出時不管a,b是小于0或等于0都按該格式輸出,輸出時a,b都保留兩位。輸入:  - 2.5 3.6 1.5 4.9輸出:  1.00+-1.30i                                                              思路:被這個要求忽悠了,我自己寫了一個暴力算的也滿分過了啊,,,我還以為必須要用結構體指針。。。就寫了兩種
#include<bits/stdc++.h>using namespace std;struct node{	double a,b;};node *add(node x,node y){	node *w=(node *)malloc(sizeof(node));	w->a=x.a+y.a;	w->b=x.b+y.b;	return w; }node *sub(node x,node y){	node *w=(node *)malloc(sizeof(node));	w->a=x.a-y.a;	w->b=x.b-y.b;	return w; }node *mul(node x,node y){	node *w=(node *)malloc(sizeof(node));	w->a=x.a*y.a-x.b*y.b;	w->b=x.a*y.b+y.a*x.b;	return w; }node *div(node x,node y){	node *w=(node *)malloc(sizeof(node));	w->a=(x.a*y.a+x.b*y.b)/(y.a*y.a+y.b*y.b);	w->b=(x.b*y.a-x.a*y.b)/(y.a*y.a+y.b*y.b);	return w; }int main(){	char c;	struct node n,m;	struct node *s;	scanf("%c %lf %lf %lf %lf",&c,&n.a,&n.b,&m.a,&m.b);	switch(c)	{		case '+':			s=add(n,m);			break;		case '-': 			s=sub(n,m);			break;		case '*':			s=mul(n,m);			break;		case '/':			s=div(n,m); 	 } 	 PRintf("%.2lf+%.2lfi",s->a,s->b);	 return 0;}
#include<stdio.h>  int main()  {      char ch;      double a,b,c,d;      scanf("%c%lf%lf%lf%lf",&ch,&a,&b,&c,&d);      if(ch=='+')      {          printf("%.2lf+%.2lfi",a+c,b+d);      }      if(ch=='-')      {          printf("%.2lf+%.2lfi",a-c,b-d);      }      if(ch=='*')      {          printf("%.2lf+%.2lfi",a*c-b*d,a*d+b*c);      }      if(ch=='/')      {          printf("%.2lf+%.2lfi",(a*c+b*d)/(c*c+d*d),(b*c-a*d)/(c*c+d*d));      }      return 0;  }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 昂仁县| 佛冈县| 洞头县| 静安区| 永安市| 嘉兴市| 左云县| 台湾省| 德安县| 寿宁县| 新乡市| 张家港市| 饶平县| 宣城市| 黄骅市| 陇西县| 南岸区| 拜城县| 武宣县| 涟源市| 和龙市| 昌邑市| 秭归县| 洪湖市| 鄂伦春自治旗| 南平市| 阿合奇县| 武胜县| 上思县| 阿拉善右旗| 正阳县| 东乡族自治县| 永康市| 高雄市| 搜索| 揭阳市| 海门市| 连平县| 江孜县| 门头沟区| 汽车|