zoukankan      html  css  js  c++  java
  • 经典c程序(0029) ---对称矩阵

    /************************************************************************************** 
    * 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]={''};
    		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]='';
    
    		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("
    ");
    		}
    		printf("
    ");
    		/////////////////////////////////////////////////////////////////////////////////////////////
    
    		// Print the answer to standard output(screen).
    
    	}
    
    	return (0);  //Your program should return 0 on normal termination.
    }
    
  • 相关阅读:
    基于asp.net + easyui框架,一步步学习easyui-datagrid——实现分页和搜索(二)
    Build CRUD Application with jQuery EasyUI
    sql里的ROW_NUMBER() OVER是啥意思?
    EasyUI实战篇之datagrid:如何重新设置datagrid所配置的属性(options)并重新查询列表(relaod)
    UNIX基础知识之程序和进程
    UNIX基础知识之输入和输出
    UNIX基础知识之文件和目录
    输出至标准出错文件的出错处理函数
    apue.h
    目录操作函数opendir、readdir和closedir
  • 原文地址:https://www.cnblogs.com/ntsk13/p/3745524.html
Copyright © 2011-2022 走看看