经典c程序(0029) ---对称矩阵

本文介绍了一种生成对称矩阵的C语言程序实现方法。该程序接收特定输入并输出一个与其转置相等的矩阵。文章包含完整的代码示例及说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/************************************************************************************** 
* Function     : test 
* Create Date  : 2014/05/22
* Author       : NTSK13 
* Email        : beijiwei@qq.com 
* Copyright    : 欢迎大家和我一起交流学习,转载请保持源文件的完整性。 
*                任何单位和个人不经本人允许不得用于商业用途 
* Version      : V0.1                    
***************************************************************************************                    
经典c程序(0029) ---对称矩阵
          
题目:
	In contemporary business administration, mathematical tools are frequently applied in order to develop the business theory.
	Numerical approaches are widely applied in the most of business characteristics because the business theories can be expressed in numerically.
	Of course, the most of business theories can be expressed by just normal terms like a conservative way.
	But, by using the mathematical methods, you may realize that more logical and clear process of theoretical development can be possible.
	So let’s enjoy the math by Symmetric matrix

	By using the first line with given input data, please output the matrix that is equal to its transpose
	For example, the given input data is A B C D, and the Symmetric Matrix is as below

	A  B  C  D
	B  A  D  C
	C  D  A  B
	D  C  B  A

	Time limit: 1 second

	[Input]

	In the first line, Input T, number of test case (T <= 10 )
	In the second line, size of the matrix” N” is given (4 ≤ N ≤ 128, N must be High-radix exponent of 2)
	In the third line, Space is separately given by number of N characteristics that is same with first line information

	[Output]

	Across the line for a given input of N to the first row, output the matrix that is diagonally symmetric matrix.
	At this time, symmetric matrix must be same with the given example.
	Each line data must be output separately as a empty

	[Input Example]

	2
	4
	B a & 2
	8
	1 2 3 4 A C B D

	[Output Example]

	B a & 2
	a B 2 &
	& 2 B a
	2 & a B

	1 2 3 4 A C B D
	2 1 4 3 C A D B
	3 4 1 2 B D A C
	4 3 2 1 D B C A
	A C B D 1 2 3 4
	C A D B 2 1 4 3
	B D A C 3 4 1 2
	D B C A 4 3 2 1

**************************************************************************************/  

#include <stdio.h>

#define M 128
int N;
char tmpChar[2];
char data[130];

int main(void)
{
	int test_case=0;
	int T=0;
	/*
	   The freopen function below opens input.txt file in read only mode, and afterward,
	   the program will read from input.txt file instead of standard(keyboard) input.
	   To test your program, you may save input data in input.txt file,
	   and use freopen function to read from the file when using scanf function.
	   You may remove the comment symbols(//) in the below statement and use it.
	   But before submission, you must remove the freopen function or rewrite comment symbols(//).
	 */
	 freopen("input.txt", "r", stdin);

	/*
	   If you remove the statement below, your program's output may not be rocorded
	   when your program is terminated after the time limit.
	   For safety, please use setbuf(stdout, NULL); statement.
	 */
	setbuf(stdout, NULL);

	scanf("%d", &T);
	for(test_case = 0; test_case < T; test_case++)
	{
		int i=0,j=0;
		int x=0,y=0;
		char result[M][M]={'\0'};
		scanf("%d", &N);

		for(i=1; i<=N; i++) {
			scanf("%s", tmpChar);
			data[i] = tmpChar[0];
		}

		/////////////////////////////////////////////////////////////////////////////////////////////
		for(i=0;i<M;i++)
		for(j=0;j<M;j++)
			result[i][j]='\0';

		for(i=2;i<N;i++)
		{
			for(x=0;x<N;x++)
			for(y=0;y<N;y++)
			{
				if( (x+y==i-1) || ( x+y==2*N-i-1 )  )
				result[x][y]=data[i];
			}

		}

		for(i=0;i<N;i++)
		for(j=0;j<N;j++)
		{
			if(i==j)
				result[i][j]=data[1];
			if(i+j==N-1)
				result[i][j]=data[N];
		}

		for(i=0;i<N;i++)
		{	for(j=0;j<N;j++)
			{
				printf("%c  ",result[i][j]);

			}
			printf("\n");
		}
		printf("\n");
		/////////////////////////////////////////////////////////////////////////////////////////////

		// Print the answer to standard output(screen).

	}

	return (0);  //Your program should return 0 on normal termination.
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值