Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,468 views
Will be added soon..
in Online Assessments by Expert (108,280 points) | 1,468 views

1 Answer

0 like 0 dislike

Problem 1 - C++ : 

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, l, r) for ((i) = (l); (i) <=(r); (i)++)
#define rep1(i, r, l) for ((i) = (r); (i) >=(l); (i)--)

int main()
{
    
    ios_base::sync_with_stdio(false) ; 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t ;
    cin>>t; ll i1=1;
    while(t--)
    {
        ll n,m ; 
        cin>>n>>m ; 
        char r[2*n+5][2*m+8];ll i ; ll j ; 
        char ok = '+';char rr='|';
        rep(i,1,2*n+1){
            
            rep(j,1,2*m+1){
                if(i%2!=0){
                   
                    if(j%2==0){
                        ok='-';
                    }
                    else
                    {
                        ok='+';
                    }
                     r[i][j] = ok ; 
                }
                else
                {
                   
                    if(j%2==0){
                        rr='.';
                    }
                    else
                    {
                        rr='|';
                    }
                     r[i][j] = rr;
                }
            }
        }
        r[1][1]='.';
        r[1][2]='.';
        r[2][1]='.';
        r[2][2]='.';
          cout<<"Case ";
          cout<<"#";cout<<i1;
          cout<<": ";i1++;
          cout<< "\n";
              rep(i,1,2*n+1){
            
            rep(j,1,2*m+1){
                cout<<r[i][j];
            }
            
            cout<<"\n";
        }
    }            
    return 0 ;  
}

/*
1)First think of the complete solution , then think of how to write it in short , then code.
2)Always spend few minutes thinking if you can directly solve the full task rather than only the small subtasks.
3)100% calm , use the scoreboard of other divisions or look at none of them.
4)..
5)..
*/
by Expert (108,280 points)