Codechef Assignment 5
Codechef Assignment 5
https://www.codechef.com/CUPA2101
#include<bits/stdc++.h>
#define ss second
#define vi vector<int>
#define ff first
int main(){
ll t;
cin>>t;
while(t--){
string s;
cin>>s;
stack<char> st;
for(ll i=0;i<s.length();i++){
if(st.empty()||st.top()!=s[i]){
st.push(s[i]);
}else{
st.pop();
cout<<st.size()<<endl;
return 0;
}
CODECHEF PRACTICE PROBLEM 5
https://www.codechef.com/CUPP2101
int main() {
// your code goes here
int n,t,a;
stack<int>stack;
cin>>t;
while(t--)
{
cin>>a;
if(a==1)
{
cin>>n;
stack.push(n);
}
else
{ if(!stack.empty()){
cout<<stack.top()<<endl;
stack.pop();}
else
cout<<"kuchbhi?"<<endl;
}
}
return 0;
}
Q. Chefs in Queue
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define modulo 1000000007
int main() {
ll n, k, i;
cin>>n>>k;
ll A[n];
stack<ll>stk;
for(i=0; i<n; i++){
cin>>A[i];
}
ll fearfull_ness=1;
for(i=0; i<n; i++){
while( !stk.empty() && A[stk.top()] > A[i] ){
fearfull_ness = (fearfull_ness % modulo) * (i-stk.top()+1) % modulo;
stk.pop();
}
stk.push(i);
}
cout<<fearfull_ness;
return 0;
}