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 1226. esreveR redrO

Why Crash (access violation) on test 9?
Posted by ilya_romanenko 24 Jul 2011 23:38
I can't find my mistakes! My program work right(i think),but i have Crash#9! WHY???
I know,that put all program is very bad...
                       C++
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
void verubad(string &m,int length)
{
    string m1;
    int a,i;
    for(i=0;i<length;i++)
        if(toupper(m[i])-'A'>=0&&toupper(m[i])-'A'<=26)m1+=m[i];
        else {
            a=i;
            break;
        }
    if(a>0){
        for(i=0;i<a/2;i++)
            {
                m1[i]=m1[i]+m1[a-1-i];
                m1[a-1-i]=m1[i]-m1[a-1-i];
                m1[i]=m1[i]-m1[a-1-i];
        }
        cout<<m1;
        for(i=a;i<length;i++)
            if(!(toupper(m[i])-'A'>=0&&toupper(m[i])-'A'<=26))cout<<m[i];
            else {
                m.erase(0,i);
                verubad(m,length-i);
                break;
            }
    }
    else {
        for(i=0;i<(length)/2;i++)
            {
                m[i]=m[i]+m[length-1-i];
                m[length-1-i]=m[i]-m[length-1-i];
                m[i]=m[i]-m[length-1-i];
        }
        cout<<m;
    }
    return;
}
int main()
{
    string m,m3;
    char c,c1,c2,c3,c4,cc;
    int length,i,length1;
    while(!cin.eof()){
        c=c1=c2=c3=c4=0;
        m3.clear();
        m.clear();
        cin.get(c);
        while(!(toupper(c)-'A'>=0&&toupper(c)-'A'<=26)&&!cin.eof()){
            cout.put(c);
            cin.get(c);
        }
        cin.putback(c);
        c=0;
        cin>>m;
        if(cin.eof()&&!m.length())return 0;
        length=m.length();
        if(length>0)
        while(!(toupper(m[length-1])-'A'>=0&&toupper(m[length-1])-'A'<=26)){
            m3+=m[length-1];
            m.erase(length-1,1);
            length--;
            if(!length)break;
        }
        length1=m3.length();
        if(length1>1)
            for(i=0;i<(length1)/2;i++)
            {
                m3[i]=m3[i]+m3[length1-1-i];
                m3[length1-1-i]=m3[i]-m3[length1-1-i];
                m3[i]=m3[i]-m3[length1-1-i];
            }
        if(length>0)
        verubad(m,length);
        if(length1)cout<<m3;
        if(c&&!cin.eof())cout<<c;
        if(!cin.eof())cin.get(c2);
        else return 0;;
        if(c2!=10)cin.putback(c2);
        else cout<<c2;
    }
    return 0;
}
But if i use void verubad(string m,int length)i have Crash (access violation) on test 1! Why? On my computer all work right!
P.S. Sorry for bad English.

Edited by author 25.07.2011 00:09
Re: Why Crash (access violation) on test 9?
Posted by S.77 31 Jul 2011 03:18
Oh. Your solution is too long. My own is just 28 lines long, including "#include" lines and all the blank ones.

Some hints for you:
1) try to process the input text char to char, that is the easiest way to get AC;
2) use "isalpha" function from "ctype.h" instead of manual checks, so don't uppercase any chars you get;
3) any non-letter chars can be processed the same way, but you should pay some extra attention to "EOF": just quit when you meet it.

Edited by author 31.07.2011 03:19