Blue Bridge Cup Password Generator

Blue Bridge Cup - Password Generator

Step 1: Convert the string to a two-dimensional array with only 6 letters in a row

Step 2: Add up each column individually

Part 3: Recursively process data until only single digits remain

Code:

#include<iostream>
#include<string>
using namespace std;

int toOnenum (int n)
	int sum = 0;
	if (n / 10 == 0) {
		return n;
	}
	else {
		while (n) {
			sum += n % 10
			n /= 10;
		}
		return toOnenum(sum);
	}
}

void change(int num[6]) {
	for (int i = 0; i < 6; i++) {
		cout << toOnenum(num[i]) << ' ';
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	string *arr;
	arr = new string[n];
	cin.get();
	for (int i = 0; i < n; i++) {
		getline(cin, arr[i]);
	}
	for (int i = 0; i < n; i++) {
		string buf = arr[i];
		int x = buf.length() / 6 + 1;
		string *str = new string[x];
		int z = 0;
		for (int j = 0; j < x; j++) {
			for (int k = 0; k < 6 && buf[z]; z++, k++) {
				str[j] += buf[z];
			}
		}
		for (int c = 0; c < x; c++, cout << endl) {
			cout << str[c];
		}
		int num[6] = { 0, 0, 0, 0, 0, 0 };
		for (int m = 0; m < x; m++) {
			for (int n = 0; n < str[m].length(); n++) {
				num[n] += str[m][n];
			}
		}
		change(num);
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325587039&siteId=291194637