Pink出于某种原因感到悲伤,他想通过听他最喜欢的乐队Pink Floyd的一些歌曲来振作起来。
有N条唱片,如果Pink按照升序收听它们,他会很高兴,例如,首先听第一首歌曲,然后听第二首歌曲,依此类推(他必须听所有N首歌曲才能成为开心)。
Pink可以按给定的顺序交付记录,他可以按照交付的顺序将记录添加到播放列表中,也可以将记录放到另一个表中。放到桌子上之后,任何时候都只能将最上面的记录添加到播放列表中。
在交付记录后打印Pink是悲伤还是快乐。
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input =
"";
process.stdin.on("data", function (input) {
stdin_input += input; // Reading input from STDIN
});
process.stdin.on("end", function () {
main(stdin_input);
});
class Stack {`enter code here`
constructor(){
this.array = [];
}
peek() {
return this.array[this.array.length-1];
}
push(value){
this.array.push(value);
return this;
}
pop(){
this.array.pop();
return this;
}
length(){
return this.array.length;
}
}
function main(input) {
const myStack = new Stack();
let a,b =[];
let l,j=1,index=0 ,x=0,y=0,v=0;
input = input.split(/\n/g);
a = input[1].split(' ');
l = a.length;
while(j<l){
x=Number(a[index]);
z=myStack.peek();
if(x == j){
b.push(j);
j++;
index++;
}
else if(myStack.length !== 0 && z == j)
{
//console.log(j);
y=myStack.peek();
b.push(y);
myStack.pop();
j++;
}
else
{
if(myStack.length === 0 )
{
myStack.push(x);
index++;
}
else if(z-x !==0)
{
v=1;
break;
}
}
}
if(v == 1){
console.log("Sad");
}
else {
console.log("Happy");
}
}
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input; // Reading input from STDIN
});
process.stdin.on("end", function () {
main(stdin_input);
});
class Stack {
constructor(){
this.array = [];
}
peek() {
return this.array[this.array.length-1];
}
push(value){
this.array.push(value);
return this;
}
pop(){
this.array.pop();
return this;
}
length(){
return this.array.length;
}
}
function main(input) {
const myStack = new Stack();
let a,b =[];
let l,j=1,index=0 ,x=0,y=0,v=0;
input = input.split(/\n/g);
a = input[1].split(' ');
l = a.length;
while(j<l){
x=Number(a[index]);
//console.log(x);
z=myStack.peek();
//console.log(z);
//console.log(myStack);
if(x == j){
b.push(j);
j++;
index++;
}
else if(myStack.length !== 0 && z == j)
{
//console.log(j);
y=myStack.peek();
// console.log(y);
b.push(y);
myStack.pop();
j++;
}
else
{
if(myStack.length === 0 )
{
myStack.push(x);
//console.log(myStack);
//console.log(b);
index++;
}
else if(z-x !==0)
{
v=1;
break;
//console.log(index);
}
}
}
//while((mystack.length)!=0 and song_to_play==stack[-1]){
//stack.pop(-1)
//song_to_play+=1
//var c = a.map(function(item) {
// return parseInt(item, 10);
//});
//var f = c.sort();
if(v == 1){
console.log("Sad");
//console.log(index);
}
else {
//console.log(b);
console.log("Happy");
}
}