【算法】Symmetric Matrix

算法描述:

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



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

[I/O Example]
Input

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

Output
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 <iostream>

using namespace std;

int N;
char tmpChar[2];
char data[130];

int main(int argc, char** argv)
{
	int test_case;
	int T;
	/*
	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 cin function.
	You may remove the comment symbols(//) in the below statement and use it.
	Use #include<cstdio> or #include<stdio.h> to use the function in your program.
	But before submission, you must remove the freopen function or rewrite comment symbols(//).
	*/
	freopen("input.txt", "r", stdin);

	cin >> T;
	for (test_case = 0; test_case < T; test_case++)
	{
		cin >> N;

		for (int i = 0; i < N; i++) {
			cin >> tmpChar;
			data[i] = tmpChar[0];
		}

		/
		/*
		Implement your algorithm here.
		The answer to the case will be stored in variable Answer.
		*/
		/

		// Print the answer to standard output(screen).
		for (int i = 0; i < N; i++)
		{
			int j;
			for (j = 0; j < N; j++) 
			{
				char c = data[i^j];
				if (j == N - 1) 
				{
					cout << c << endl;
				}
				else {
					cout << c;
				}
			}
		}
		cout << endl;
	}

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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值