From bf3ead14901a29d9adbbed7d329daf347cf7a16a Mon Sep 17 00:00:00 2001 From: Aritra Banerjee Date: Fri, 1 Oct 2021 22:31:26 +0530 Subject: [PATCH 1/2] added POPGATE solution --- CodeChef Problems/POPGATES/problem.md | 35 +++++++++++++++++ CodeChef Problems/POPGATES/solution.c | 54 +++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 CodeChef Problems/POPGATES/problem.md create mode 100644 CodeChef Problems/POPGATES/solution.c diff --git a/CodeChef Problems/POPGATES/problem.md b/CodeChef Problems/POPGATES/problem.md new file mode 100644 index 0000000..0e14859 --- /dev/null +++ b/CodeChef Problems/POPGATES/problem.md @@ -0,0 +1,35 @@ +**Link to problem:** https://www.codechef.com/problems/POPGATES + +**Description:** + + + +**Input:** + + + +**Output:** + + + +**Constraints:** + + + + **Subtasks:** + + **Subtask #1 (100 points):** original constraints + + **Example Input:** + + + + **Example Output:** + + + + **Explanation:** + + **Example case 1:** + + **Example case 2:** diff --git a/CodeChef Problems/POPGATES/solution.c b/CodeChef Problems/POPGATES/solution.c new file mode 100644 index 0000000..77884f2 --- /dev/null +++ b/CodeChef Problems/POPGATES/solution.c @@ -0,0 +1,54 @@ +//author : Aritra Banerjee + +#include +#include +int main() +{ + int T; + scanf("%d",&T); + while(T--) + { + int N,K,i,j,x; + scanf("%d %d",&N,&K); + char a[N]; + for(i=0;i=N-K;i--) + { + if(a[i]=='T') + { + a[i]=a[i+1]; + } + else if(a[i]=='H') + { + for(x=0;x Date: Fri, 1 Oct 2021 22:43:05 +0530 Subject: [PATCH 2/2] Update problem.md --- CodeChef Problems/POPGATES/problem.md | 43 +++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/CodeChef Problems/POPGATES/problem.md b/CodeChef Problems/POPGATES/problem.md index 0e14859..8505c96 100644 --- a/CodeChef Problems/POPGATES/problem.md +++ b/CodeChef Problems/POPGATES/problem.md @@ -1,35 +1,66 @@ **Link to problem:** https://www.codechef.com/problems/POPGATES -**Description:** +**Description:** + +You are Dastan, the great Prince of Persia! + +After searching long for the mysterious 'Sands of Time', you have finally arrived at the gates of the city that hosts the ancient temple of the gods. However, the gate is locked and it can only be opened with a secret code, which you need to obtain by solving the following puzzle: + +There is a table in front of you, with N coins placed in a row and numbered 1 through N from left to right. For each coin, you know whether it is initially showing heads or tails. You have to perform exactly K operations. In one operation, you should remove the rightmost coin present on the table, and if this coin was showing heads right before it was removed, then you should also flip all the remaining coins. (If a coin was showing heads, then after it is flipped, it is showing tails, and vice versa.) + +The code needed to enter the temple is the number of coins which, after these K operations are performed, have not been removed and are showing heads. Can you find this number? The fate of Persia lies in your hands… **Input:** +- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +- The first line of each test case contains two space-separated integers N and K. +- The second line contains N space-separated characters. For each valid i, the i-th of these characters is 'H' if the i-th coin is initially showing heads or 'T' if it is showing tails. + **Output:** +For each test case, print a single line containing one integer ― the number of coins that are showing heads after K operations. + **Constraints:** + +- 1≤T≤200 +- 1≤K