求两组数的平均值

有2组数据,每组有30个数据,这两组数据的最大值都是17。两组数据中编号相同的数据之和,以及两组数据中编号相同的数据与17的差值已知。确定这两组数据有无差错。若无差错,求出它们的平均值。

cpp 复制代码
#include <stdio.h>
#define N 11
#define M 9
#define Q 10
#define total (N+M+Q)
 
typedef struct ELE *x_ptr;
struct ELE {              //存放两组数的平均值
	float f1;
	float f2;
};

int aver(char r[][2],char *p,char k,x_ptr ave);

int main()
{
	struct ELE model;
    char a1[N][2]={{0,-4},{0,-4},{0,-4},{0,-4},{0,-4},{0,-4},
                 {0,-5},{0,0},{-2,0},{-2,-6},{-2,-4}};
	char s1[N]={30,30,30,30,30,30,29,34,32,26,28};
	char a2[Q][2]={{0,0},{0,-4},{0,-4},{0,-4},{0,-4},{0,-6},{0,-6},{0,0},
	               {-1,-6},{0,-4}};
	char s2[Q]={34,30,30,30,30,28,28,34,27,30};
	char a3[M][2]={{0,0},{0,0},{0,-6},{0,0},{-1,-4},{0,-4},
                  {0,-6},{-1,0},{0,-4}};
	char s3[M]={34,34,28,34,29,30,28,33,30};             
	static int i0,i1,i2;
	float x,y;
	
	model.f1=0;
	model.f2=0;
	i0=aver(a1,s1,N,&model);
	i1=aver(a2,s2,Q,&model);
	i2=aver(a3,s3,M,&model);
	if(i0==0 && i1==0 && i2==0)
	  printf("%.2f\n %.2f\n", model.f1,model.f2);
	 
	return 0;
	
}
	
	
int aver(char r[][2],char *p,char k,x_ptr ave)
{
	char i,j,W;
	int sum1=0,sum2=0;
	W=k;
	for(i=0;i<W;i++)
		if( p[i] != 34+(r[i][0]+r[i][1]) )
			break;
	if(i==W)
	{
		for(j=0;j<W;j++)
		{
		 sum1+=17+r[j][0];
		 sum2+=17+r[j][1];
		}
	  ave->f1 += sum1/(total*1.0);
	  ave->f2 += sum2/(total*1.0);
	}
	else
	{
		return -1;
	}
  
	return 0;
}
相关推荐
leaves falling20 小时前
迭代实现 斐波那契数列
数据结构·算法
珂朵莉MM21 小时前
全球校园人工智能算法精英大赛-产业命题赛-算法巅峰赛 2025年度画像
java·人工智能·算法·机器人
Morwit21 小时前
*【力扣hot100】 647. 回文子串
c++·算法·leetcode
DonnyCoy21 小时前
Android性能之数据结构
数据结构
天赐学c语言21 小时前
1.7 - 删除排序链表中的重要元素II && 哈希冲突常用解决冲突方法
数据结构·c++·链表·哈希算法·leecode
tobias.b21 小时前
408真题解析-2009-13-计组-浮点数加减运算
算法·计算机考研·408考研·408真题
菜鸟233号1 天前
力扣96 不同的二叉搜索树 java实现
java·数据结构·算法·leetcode
Coovally AI模型快速验证1 天前
超越Sora的开源思路:如何用预训练组件高效训练你的视频扩散模型?(附训练代码)
人工智能·算法·yolo·计算机视觉·音视频·无人机
千金裘换酒1 天前
Leetcode 有效括号 栈
算法·leetcode·职场和发展