ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1008. Image Encoding

Help
Posted by Mukul Barai 9 Jan 2017 17:36
Please someone tell me where is the wrong in my code.

#include <iostream>
#include <queue>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
struct dott{
    int x;
    int y;
};
int main()
{
    char str[8];
    gets(str);
    if(strlen(str) <= 2){
        int a, b, n;
        n = atoi(str);
        bool XY[200][200];
        memset(XY, 0, sizeof(XY));
        struct dott center;
        cin>>a>>b;
        center.x = a;
        center.y = b;
        for(int i=2; i<=n; i++){
            cin>>a>>b;
            XY[a][b] = 1;
        }
        queue<dott> qu;
        qu.push(center);
        cout<<center.x<<" "<<center.y<<"\n";
        while(!qu.empty()){
            dott pix = qu.front();
            qu.pop();
            if(XY[pix.x + 1][pix.y] == 1){
                cout<<"R";
                center.x = pix.x + 1;
                center.y = pix.y;
                qu.push(center);
                XY[pix.x + 1][pix.y] = 0;
            }
            if(XY[pix.x][pix.y + 1] == 1){
                cout<<"T";
                center.x = pix.x;
                center.y = pix.y + 1;
                qu.push(center);
                XY[pix.x][pix.y + 1] = 0;
            }
            if(XY[pix.x - 1][pix.y] == 1){
                cout<<"L";
                center.x = pix.x - 1;
                center.y = pix.y;
                qu.push(center);
                XY[pix.x - 1][pix.y] = 0;
            }
            if(XY[pix.x][pix.y - 1] == 1){
                cout<<"B";
                center.x = pix.x;
                center.y = pix.y - 1;
                qu.push(center);
                XY[pix.x][pix.y - 1] = 0;
            }
            if(!qu.empty()){
                cout<<",\n";
            }
            else{
                cout<<".";
            }
        }
    }
    else{
        int a, b, count=0;
        bool XY[200][200];
        memset(XY, 0, sizeof(XY));
        struct dott centre;
        char *s;
        s = strtok(str," ");
        a = atoi(s);
        s = strtok(NULL," ");
        b = atoi(s);
        XY[a][b] = 1;
        centre.x = a;
        centre.y = b;
        queue<dott> qu;
        qu.push(centre);
        string str[200];
        for(int i=0; ;i++){
            cin>>str[i];
            if(str[i] == "."){
                break;
            }
            count++;
        }
        for(int i=0; i<count; i++){
            dott S = qu.front();
            qu.pop();
            for(int j=0; j<str[i].size(); j++){
                if(str[i][j] == 'R'){
                    XY[S.x+1][S.y] = 1;
                    centre.x = S.x+1;
                    centre.y = S.y;
                    qu.push(centre);
                }
                if(str[i][j] == 'T'){
                    XY[S.x][S.y+1] = 1;
                    centre.x = S.x;
                    centre.y = S.y+1;
                    qu.push(centre);
                }
                if(str[i][j] == 'L'){
                    XY[S.x-1][S.y] = 1;
                    centre.x = S.x-1;
                    centre.y = S.y;
                    qu.push(centre);
                }
                if(str[i][j] == 'B'){
                    XY[S.x][S.y-1] = 1;
                    centre.x = S.x;
                    centre.x = S.y-1;
                    qu.push(centre);
                }
            }

        }
        cout<<count+1<<"\n";
        for(int i=0; i<100; i++){
            for(int j=0; j<100; j++){
                if(XY[i][j] == 1){
                    cout<<i<<" "<<j<<"\n";
                }
            }
        }
    }
    return 0;
}

Edited by author 09.01.2017 17:37