Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:33:05
Task:HIIT Generation
Sender:Karhukopla
Submission time:2018-05-26 11:33:05
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:52:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   swap(q, ns[c]);
               ^
input/code.cpp:53:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < q.size(); i++) {
                   ~~^~~~~~~~~~

Code

#include <bits/stdc++.h>

#define ll long long
#define lll __int128
#define pii pair<int, int>
#define M 1000000007
#define N (1<<20)
using namespace std;

struct node {
	char v;
	vector<node*> ch;
	node (char c) {
		v = c;
		ch = {};
	}
};

vector<node*> ns[255];

void push (node* &n) {
	n->ch.push_back(new node('H'));
	n->ch.push_back(new node('I'));
	n->ch.push_back(new node('I'));
	n->ch.push_back(new node('T'));
	ns['H'].push_back(n->ch[0]);
	ns['I'].push_back(n->ch[1]);
	ns['I'].push_back(n->ch[2]);
	ns['T'].push_back(n->ch[3]);
}

void print (node* n) {
	if (n->ch.empty()) cout<<(n->v);
	else {
		print(n->ch[0]);
		print(n->ch[1]);
		print(n->ch[2]);
		print(n->ch[3]);
	}
}

int main () {
	node* root = new node('*');
	push(root);
	int n;
	cin>>n;
	while (n --> 0) {
		char c;
		cin>>c;
		
		vector<node*> q;
		swap(q, ns[c]);
		for (int i = 0; i < q.size(); i++) {
			push(q[i]);
		}
	}
	print(root);
	cout<<endl;
}