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

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

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

2019-11-11 01:09:06
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
  算法訓(xùn)練 P1103  時(shí)間限制:1.0s   內(nèi)存限制:256.0MB        編程實(shí)現(xiàn)兩個(gè)復(fù)數(shù)的運(yùn)算。設(shè)有兩個(gè)復(fù)數(shù) 和 ,則他們的運(yùn)算公式為:  要求:(1)定義一個(gè)結(jié)構(gòu)體類型來(lái)描述復(fù)數(shù)。  (2)復(fù)數(shù)之間的加法、減法、乘法和除法分別用不用的函數(shù)來(lái)實(shí)現(xiàn)。  (3)必須使用結(jié)構(gòu)體指針的方法把函數(shù)的計(jì)算結(jié)果返回。  說(shuō)明:用戶輸入:運(yùn)算符號(hào)(+,-,*,/) a b c d.  輸出:a+bi,輸出時(shí)不管a,b是小于0或等于0都按該格式輸出,輸出時(shí)a,b都保留兩位。輸入:  - 2.5 3.6 1.5 4.9輸出:  1.00+-1.30i                                                              思路:被這個(gè)要求忽悠了,我自己寫了一個(gè)暴力算的也滿分過(guò)了啊,,,我還以為必須要用結(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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 来凤县| 弥渡县| 二连浩特市| 昌乐县| 惠来县| 罗甸县| 百色市| 晋州市| 白山市| 高安市| 广丰县| 海阳市| 黎城县| 信宜市| 武胜县| 万山特区| 卓尼县| 尖扎县| 澄江县| 张家界市| 乌什县| 彰武县| 双牌县| 上虞市| 彰武县| 新邵县| 伊金霍洛旗| 温宿县| 郑州市| 科技| 抚松县| 南城县| 虹口区| 斗六市| 珠海市| 沈阳市| 祁门县| 梅河口市| 通江县| 新乡县| 伊宁市|