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 1496. Spammer

Crash (Acess Violation) on case # 6?
Posted by HappyPerson 11 Jul 2012 00:29
Code:


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{int spammers; char peeps[33][101]; bool k=true;
    cin>>spammers;
    for(int i=0; i<=spammers; i++)
    {
            peeps[31][i]=0;
            peeps[32][i]=0;
            for(int g=0; peeps[g-1][i]!='\n'; g++)
            {
                    cin.get(peeps[g][i]);
                    peeps[31][i]+=peeps[g][i];
                    peeps[32][i]++;
            }
    }
    for(int i=0; i<=spammers-1; i++)
    {
               for(int g=i+1; g<=spammers; g++)
               {
                       if(peeps[31][i]==peeps[31][g] && peeps[32][i]==peeps[32][g] && peeps[31][g]!=-1)
                       {
                                                     if(k==true)
                                                     {
                                                     peeps[31][g]=-1;
                                                     for(int y=0; peeps[y-1][g]!='\n'; y++)
                                                     {
                                                             cout<<peeps[y][g];
                                                     }
                                                     k=false;
                                                     }
                                                     else
                                                     {
                                                         peeps[31][g]=-1;
                                                     }
                       }
               }
               k=true;
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}





Any ideas why it crashes?
Use "reference vector<T>::at(size_t i);", Luke!
Posted by Artem Khyzha 11 Jul 2012 00:47
Sorry, your code is kind of too obfuscated for lazy me, but I would believe that you've really got access violation in your program. If you're curious, replace all arrays with vectors and use range checking access via "at".