1 / 8
Jun 2016

On my computer and some others my code is working good but at spoj it telling me it is wrong.

`#include
using namespace std;
int main() {
int n, g[4];
cin >> n;
char t[200][200];

for (int i=0; i<4; i++) for (int l=0; l<101; l++) t[i][l] = 0;
for(int z=0; z<n; z++) {
    cin >> t[z];
}

for(int i=0, f=0; i<n; i++) {
    for(int l=0; l<101; l++) {
        if(t[i][l]==0) {
            g[f] = l;
            f++;
            break;
        }
    }
}

for(int i=0; i<n; i++) {
    for(int l=0; l<(g[i]/2); l++) {
        if(l%2==0) cout << t[i][l];
    }
    cout << endl;
}

}`

  • created

    Jun '16
  • last reply

    Jul '16
  • 7

    replies

  • 1.5k

    views

  • 3

    users

  • 2

    links

Your code does not wok correctly - if I guess right and you mean this code:

#include <iostream>
using namespace std;
int main()
{
    int n, g[4];
    cin >> n;
    char t[200][200];
    for (int i=0; i<4; i++) for (int l=0; l<101; l++) t[i][l] = 0;
for(int z=0; z<n; z++) {
    cin >> t[z];
}

for(int i=0, f=0; i<n; i++) {
    for(int l=0; l<101; l++) {
        if(t[i][l]==0) {
            g[f] = l;
            f++;
            break;
        }
    }
}

for(int i=0; i<n; i++) {
    for(int l=0; l<(g[i]/2); l++) {
        if(l%2==0) cout << t[i][l];
    }
    cout << endl;
}
}

What do you think are the "corner cases" in this problem?

ok, I found my mistake :slight_smile:

#include <iostream>
using namespace std;

int main() {
    int n, g[200];
    cin >> n;
    char t[200][200];
    for(int i=0; i<n; i++) for(int l=0; l<200; l++) t[i][l] = 0;
    
    for(int z=0; z<n; z++) {
        cin >> t[z];
    }
    
    for(int i=0, f=0; i<n; i++) {
        for(int l=0; l<200; l++) {
            if(t[i][l]==0) {
                g[f] = l;
                f++;
                break;
            }
        }
    }

    for(int i=0; i<n; i++) {
        for(int l=0; l<(g[i]/2); l++) {
            if(l%2==0) cout << t[i][l];
        }
        cout << endl;
    }
}

Great.
btw., what did you do to get this code style with syntax highlighting?

27 days later

using namespace std;

int main(){
int test, t, i, j;

cin>>test;

int len[test];
char str[test][200];

for(t=0;t<test;t++)     cin>>str[t];

for(t=0;t<test;t++)     len[t]=strlen(str[t]);

for(i=0;i<test;i++){
        if(i==0)    for(j=0;j<(len[0]/2);j++){
                if(j==0)        cout<<str[0][0];
        }
        else if(i>0)    for(j=0;j<(len[i]/2);j++){
                if(!(j%2)) cout<<str[i][j];
        }
        cout<<endl;
}

return 0;

}

(sorry i wasn't allowed to upload files now)