2312:顺序排列【数组】。

2024-04-27 03:38
文章标签 数组 2312 顺序排列

本文主要是介绍2312:顺序排列【数组】。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目描述

编写一个过程,对一个n×n的矩阵,通过行变换,使其每行元素的平均值按递增顺序排列

输入

4

5 5 5 5

4 4 4 4

3 3 3 3

1 1 1 1

输出

1 1 1 1

3 3 3 3

4 4 4 4

5 5 5 5

样例输入

<span style="color:#333333">3
1 2 3
4 5 6
1 1 1</span>

样例输出

<span style="color:#333333">1 1 1
1 2 3
4 5 6</span>
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100typedef struct {int data[MAXSIZE];int average;
}Line;typedef struct {Line *column[MAXSIZE];int length;
}Array;int main() {int n;scanf("%d",&n);int i,j;int sum;Array array;for(i=0;i<n;i++){Line *line;line=(Line *)malloc(sizeof(Line));sum=0;for(j=0;j<n;j++){scanf("%d",&line->data[j]);sum+=line->data[j];}line->average=(sum/n)*100;array.column[i]=line;}Line *line1;int maxIndex;for(i=0;i<n-1;i++){//line1=array.column[0];maxIndex=0;for (j = 1; j< n-i; ++j) {if(array.column[j]->average>array.column[maxIndex]->average){maxIndex=j;//line1=array.column[j];}}line1=array.column[n-i-1];array.column[n-i-1]=array.column[maxIndex];array.column[maxIndex]=line1;}for ( i = 0; i <n ; ++i) {for(j=0;j<n;j++){printf("%d",array.column[i]->data[j]);if(j!=n-1){printf(" ");} else{printf("\n");}}}return 0;
}

 

这篇关于2312:顺序排列【数组】。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/939429

相关文章

hdu2241(二分+合并数组)

题意:判断是否存在a+b+c = x,a,b,c分别属于集合A,B,C 如果用暴力会超时,所以这里用到了数组合并,将b,c数组合并成d,d数组存的是b,c数组元素的和,然后对d数组进行二分就可以了 代码如下(附注释): #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<que

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while

C语言:柔性数组

数组定义 柔性数组 err int arr[0] = {0}; // ERROR 柔性数组 // 常见struct Test{int len;char arr[1024];} // 柔性数组struct Test{int len;char arr[0];}struct Test *t;t = malloc(sizeof(Test) + 11);strcpy(t->arr,

C 语言基础之数组

文章目录 什么是数组数组变量的声明多维数组 什么是数组 数组,顾名思义,就是一组数。 假如班上有 30 个同学,让你编程统计每个人的分数,求最高分、最低分、平均分等。如果不知道数组,你只能这样写代码: int ZhangSan_score = 95;int LiSi_score = 90;......int LiuDong_score = 100;int Zhou

计算数组的斜率,偏移,R2

模拟Excel中的R2的计算。         public bool fnCheckRear_R2(List<double[]> lRear, int iMinRear, int iMaxRear, ref double dR2)         {             bool bResult = true;             int n = 0;             dou

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

PHP7扩展开发之数组处理

前言 这次,我们将演示如何在PHP扩展中如何对数组进行处理。要实现的PHP代码如下: <?phpfunction array_concat ($arr, $prefix) {foreach($arr as $key => $val) {if (isset($prefix[$key]) && is_string($val) && is_string($prefix[$key])) {$arr[

Go 数组赋值问题

package mainimport "fmt"type Student struct {Name stringAge int}func main() {data := make(map[string]*Student)list := []Student{{Name:"a",Age:1},{Name:"b",Age:2},{Name:"c",Age:3},}// 错误 都指向了最后一个v// a

码蹄集部分题目(2024OJ赛9.4-9.8;线段树+树状数组)

1🐋🐋配对最小值(王者;树状数组) 时间限制:1秒 占用内存:64M 🐟题目思路 MT3065 配对最小值_哔哩哔哩_bilibili 🐟代码 #include<bits/stdc++.h> using namespace std;const int N=1e5+7;int a[N],b[N],c[N],n,q;struct QUERY{int l,r,id;}que

【第0006页 · 数组】寻找重复数

【前言】本文以及之后的一些题解都会陆续整理到目录中,若想了解全部题解整理,请看这里: 第0006页 · 寻找重复数         今天想讨论的一道题在 LeetCode 上评论也是颇为“不错”。有一说一,是道好题,不过我们还是得先理解了它才算真正的好题。这里我们展示一种使用二进制的做法,希望能帮到你哟! 【寻找重复数】给定一个包含 n + 1 个整数的数组 nums ,其数字都