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.
    }
    
  • 相关阅读:
    oracle客户端连接服务器基本教程
    java中字符串处理、串联和转换的几个常用方法,以及如果需要自己编程实现的具体实施步骤。
    面试相关
    java中byte是什么类型,和int有什么区别
    (华为机试大备战)java。多了解了解最常用的那个类库的方法对处理字符串的方法
    (华为)以下代码片段将创建一个仅保存大写字符的字段。
    (华为)以下代码片段将创建一个仅保存大写字符的字段。
    每个程序中只有一个public类,主类?
    我的第一个长程序,虽然是直接抄了书上,可是还是出现了两次拼写错误,最终还是找到异常的答案,改过来了。
    实践证明:当类想实现两个监听接口的时候,必须把两个都设置成内部类,不可能一个是外部类实现,一个是内部类实现。这样容易捕获错误,出现异常。
  • 原文地址:https://www.cnblogs.com/ntsk13/p/3745524.html
Copyright © 2011-2022 走看看