1042 Shuffling Machine (20 minutes) / simple analog / observation Law

Topic Link
started not to think too much, directly to the face value of each card are as a string object. Since the function of VS2017 there Alternatively, after losing S1 ~ S13, replace, you do not need all the hand knock. The advantage is that do not need to think about, but the code somewhat jumbled.

#include<iostream>
#include<string>
using namespace std;
int main() {
	string s[55] = {" ", "S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13",
		"H1","H2","H3","H4","H5","H6","H7","H8","H9","H10","H11","H12","H13",
		"C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13",
		"D1","D2","D3","D4","D5","D6","D7","D8","D9","D10","D11","D12","D13" ,
		"J1","J2" };
	string an[55];
	int order[55],k;
	cin >> k;
	for (int i = 1; i <= 54; i++) {
		cin >> order[i];
	}
	while (k--) {
		for (int i = 1; i <= 54; i++) {
			an[order[i]] = s[i];
		}
		for (int i = 1; i <= 54; i++) {
			s[i] = an[i];  //保存每次操作的结果
		}
	}
	cout << an[1];
	for (int i = 2; i <= 54; i++) {
		cout << " " << an[i];
	}
	return 0;
}

Observation can be found, the order of the beginning of the sign face is very regular, so you can determine the face value of cards according to the order.

#include<iostream>
using namespace std;
int main() {
	char ma[] = "SHCDJ"; //映射表
	int an[55],t[55],order[55], k;
	cin >> k;
	for (int i = 1; i <= 54; i++) {
		cin >> order[i];
		t[i] = i;  //初始化
	}
	while (k--) {
		for (int i = 1; i <= 54; i++) {
			an[order[i]] = t[i];
		}
		for (int i = 1; i <= 54; i++) {
			t[i] = an[i]; //保存每次操作的结果
		}
	}
	for (int i = 1; i <= 54; i++) {
		if (i != 1) cout << " ";
		an[i] = an[i] - 1;
		cout << ma[an[i]/13]<<an[i]%13+1;
	}
	return 0;
}
Published 26 original articles · won praise 5 · Views 419

Guess you like

Origin blog.csdn.net/weixin_43590232/article/details/104088634