Please help me with the c++ code (Logic is write but Error in inputing using getline(cin,s))

https://toph.co/arena?contest=intra-uap-2020-r#!/p/5f2d4f9cc9317400015674aa

#IT is not live Just a practice Contest running

MY code -

void solve()
{
int t;
cin >> t;

while(t--) {
    int n,m;
    cin >> n >> m;

    string str;
    cin.ignore();
    getline(cin,str);

    int l = str.length();
    
    char mat[n][m] , Mat[n][m];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            mat[i][j] = ' ';
            Mat[i][j] = ' ';
        }
    }

  //  cout << s << endl;

    int k = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(k < l)
            {
                mat[i][j] = str[k];
                k++;
            }
            else
            {
                break;
            }
            
        }

        if(k >= l) break;
    }

    


    for(int j = 0; j < m; j++)
    {
        char c;
        int times;
        cin >> c >> times;

        if(c == 'D')
        {
            for(int i = 0; i < n; i++)
            {
                Mat[(i + times)%n][j] = mat[i][j];
            }
        }
        else
        {
            for(int i = 0; i < n; i++)
            {
                Mat[(i -  times + n)%n][j] = mat[i][j];
            }
        }

    }


    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cout << Mat[i][j];
        }
    }
    cout << endl;

}

}

The question link requires login details.

1 Like

Problem :-
In cryptography a cipher ( or cypher ) is an algorithm for performing encryption or decryption-a series of well-defined steps that can be followed as a procedure. An alternative, less common term is encipherment. To encipher or encode is to convert information into cipher or code. In common parlance, “cipher” is synonymous with code, as they are both a set of steps that encrypt a message; however, the concepts are distinct in cryptography, especially classical cryptography.

In this problem you have to implement one basic encryption method. You will be given a NN x MMmatrix and a string SS containing uppercase English letters only along with an instruction set containing MM number of instructions. Each instruction of the instruction set will contain one uppercase character UU or DD followed by an integer KK. For iith instruction of the instructions set, you have to shift each character of matrix’s iith column KK times upward if the iith instruction’s character is UU. Otherwise, you have to shift each character of matrix’s iith column KK times downward. Note that the matrix is circular that means it’s first row is connected with it’s last one.

Input

First line contains an integer TT , numbers of test cases. ( 1 <= T <= 10001<=T<=1000 ). For each test case,The first line will contain two integers NN ( 1 <= N <= 1001<=N<=100 ) and MM ( 1 <= M <= 10001<=M<=1000 ) numbers of row and column of the matrix. Second line will contain a string SS ( 1 <= | S | <= N1<=∣S∣<=NxMM ) containing uppercase letters only. Then there will be MM lines of instruction to be performed on the matrix. Each line contains one uppercase character U or D followed by an integer KK ( 0 <= K <= 1000000<=K<=100000 )

Output

Output the string after encryption operation.

It is difficult for me to share example and test cases…