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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

藍(lán)橋杯算法訓(xùn)練 P1103 結(jié)構(gòu)體指針or 暴力

2019-11-11 02:37:12
字體:
供稿:網(wǎng)友
  算法訓(xùn)練 P1103  時間限制:1.0s   內(nèi)存限制:256.0MB        編程實現(xiàn)兩個復(fù)數(shù)的運算。設(shè)有兩個復(fù)數(shù) 和 ,則他們的運算公式為:  要求:(1)定義一個結(jié)構(gòu)體類型來描述復(fù)數(shù)?! 。?)復(fù)數(shù)之間的加法、減法、乘法和除法分別用不用的函數(shù)來實現(xiàn)?! 。?)必須使用結(jié)構(gòu)體指針的方法把函數(shù)的計算結(jié)果返回?! ≌f明:用戶輸入:運算符號(+,-,*,/) a b c d.  輸出:a+bi,輸出時不管a,b是小于0或等于0都按該格式輸出,輸出時a,b都保留兩位。輸入:  - 2.5 3.6 1.5 4.9輸出:  1.00+-1.30i                                                              思路:被這個要求忽悠了,我自己寫了一個暴力算的也滿分過了啊,,,我還以為必須要用結(jié)構(gòu)體指針。。。就寫了兩種
#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;  }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 玉溪市| 夏河县| 宁城县| 湘阴县| 泊头市| 西丰县| 噶尔县| 高陵县| 绍兴县| 嘉兴市| 井陉县| 石阡县| 南康市| 灵武市| 苏州市| 巴南区| 威海市| 荔浦县| 澜沧| 宁强县| 牙克石市| 中超| 八宿县| 清水县| 稻城县| 萝北县| 本溪市| 平罗县| 宁海县| 兴仁县| 霞浦县| 福海县| 万载县| 苗栗市| 廉江市| 榆林市| 特克斯县| 仁布县| 松滋市| 阿图什市| 渝北区|