I have posted a solution with a detailed explanation here on my blog :- 
https://www.golibrary.co/google-codejam-2020-solution-to-nesting-depth-problem/




On Tuesday, 7 April 2020 10:56:20 UTC+10, Avinash Bhardwaj wrote:
>
>
> I prepared several testcases and each one is passing as per the rules 
> stated in the problem. But still I get WA: wrong answer. Could anyone point 
> me out to a possible case where my solution fails? It'd be great help
>
> #include <iostream>
> #include <string>
> #include <deque>
> using namespace std;
>
> int main()
> { 
> int T , N ;
> cin >> T ;
> for(int it = 1 ; it <= T ; ++it)
> {
>     string input ;
> string output ;
>         cin >> input ;
> int nc_open = 0 ;
> deque<char> tailstr ;
> for(auto digit : input)
> {
> int num = digit - '0' ;
> if(nc_open <= num)
> {
> int nc_add = num - nc_open ;
> string temp(nc_add, '(');
> temp += digit ;
> output += temp;
> for(int k = 0 ; k < nc_add ; ++k)
> {
>     tailstr.push_back(')');
> }
> nc_open = num;
> }
> else
> {
> int extra_par = nc_open - num ;
> for(auto i = 1 ; i <= extra_par ; ++i)
> {
> output += tailstr.back();
> tailstr.pop_back();
> }
> nc_open = num ;
> output += digit ;
> }
> }
> for(auto ch: tailstr)
> output += ch ;
> output += '\0' ;
> cout << "Case #"<< it << ": " << output << endl;
> }
> return 0 ;
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/295ffd4a-855e-434a-91ab-c79d592f8656%40googlegroups.com.

Reply via email to