The correct solution isn't far from your idea, Small explanation in white below, if you have another background color, sorry: Instead of the chars from minJ to maxJ each line keep a global gminJ gmaxJ, where gminJ is min of all minJ and gmaxJ is max of all maxJ. Then, print all lines from A[0] to A[A.size() - 1], not just in A, all chars in the range gminJ and gmaxJ, and print a '\n' or std::endl at the end of each line.
Carlos Guía On Fri, May 28, 2010 at 2:30 PM, Aamir Khan <aamir.cod...@gmail.com> wrote: > oh i got it..... > i got my mistake but still don't know what should be the right code... > or right algorithm... > > by the way thanks to everybody who helped me... > > > On May 28, 11:14 pm, Carlos Guia <zyx3d...@gmail.com> wrote: > > I'm pretty sure Bharath is right on that one. A.at(A.size()) is going to > > throw an exception no matter the size or values of A. Changing that may > not > > make the algorithm right, but that instruction is wrong nevertheless, it > is > > always accessing an element outside A's range. > > > > The algorithm itself has other errors, you must print the rectangle that > > encloses the image, not process lines independently. For example: > > > > Input > > .... > > *.*. > > ..*. > > .... > > *... > > > > Correct output > > *.* > > ..* > > ... > > *.. > > > > Your logic's output: > > *.* > > * > > * > > > > Carlos Guía > > > > On Fri, May 28, 2010 at 1:16 PM, Aamir Khan <aamir.cod...@gmail.com> > wrote: > > > i have written i<A.size().....not i<=A.size().... > > > i think thats not error..and i have tried it also > > > > > On May 28, 5:35 pm, Bharath Raghavendran <rbharat...@gmail.com> wrote: > > > > I dont know what the question is or what the algo is supposd to do. > But > > > i > > > > guess the error is happening at this point : > > > > A.at(A.size()) > > > > > > maybe you need to do A.at(A.size()-1) ? > > > > > > On 28 May 2010 17:49, Aamir Khan <aamir.cod...@gmail.com> wrote: > > > > > > > I was doing some practice for codeforces round 15 to be held in > around > > > > > 27 hours from now.... > > > > > I have written the C++ source code for codeforces round 14/A > problem > > > > > (Letter)... > > > > > I am getting runtime error which i am not able to understand... > > > > > Please help.. > > > > > > > Error: > > > > > > > terminate called after throwing an instance of 'std::out_of_range' > > > > > what(): vector::_M_range_check > > > > > Aborted > > > > > > > Source Code: > > > > > /************** > > > > > Header Files > > > > > **************/ > > > > > > > #include <iostream> > > > > > #include <vector> > > > > > #include <cstdio> > > > > > #include <cstdlib> > > > > > #include <stdexcept> > > > > > #include <string> > > > > > #include <iomanip> > > > > > > > using namespace std; > > > > > > > typedef vector<int> vi; > > > > > > > int main() > > > > > { > > > > > int row,col; > > > > > cin>>row>>col; > > > > > const int cols=col; > > > > > const int rows=row; > > > > > char Array[rows][cols]; > > > > > string sentence; > > > > > vi A; > > > > > vi B; > > > > > > > for(int i=0;i<rows;i++) > > > > > { cin>>sentence; > > > > > for (int j=0;j<cols;j++) > > > > > { Array[i][j]=sentence[j]; > > > > > if (Array[i][j]=='*') > > > > > { A.push_back(i); > > > > > B.push_back(j); } > > > > > > > } > > > > > } > > > > > > > for(int i=A.at(0);i<A.at(A.size());i++) > > > > > { > > > > > int max_B=0; > > > > > int min_B=row-1; > > > > > for ( unsigned l=0;l<B.size();l++) > > > > > { > > > > > if(max_B < B.at(l)) > > > > > max_B=B.at(l); > > > > > if(min_B > B.at(l)) > > > > > min_B=B.at(l); > > > > > } > > > > > > > for (int j=min_B;j<max_B;j++) > > > > > { cout<<Array[i][j]; > > > > > } > > > > > } > > > > > > > cin.get(); > > > > > cin.ignore(); > > > > > return 0; > > > > > } > > > > > > > And if you have better algorithm to solve the problem then please > > > > > share it here.... > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "google-codejam" group. > > > > > To post to this group, send email to google-c...@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > google-code+unsubscr...@googlegroups.com<google-code%2bunsubscr...@googlegroups.com> > <google-code%2bunsubscr...@googlegroups.com<google-code%252bunsubscr...@googlegroups.com> > > > > > <google-code%2bunsubscr...@googlegroups.com<google-code%252bunsubscr...@googlegroups.com> > <google-code%252bunsubscr...@googlegroups.com<google-code%25252bunsubscr...@googlegroups.com> > > > > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/google-code?hl=en. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "google-codejam" group. > > > To post to this group, send email to google-c...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > google-code+unsubscr...@googlegroups.com<google-code%2bunsubscr...@googlegroups.com> > <google-code%2bunsubscr...@googlegroups.com<google-code%252bunsubscr...@googlegroups.com> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/google-code?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "google-codejam" group. > To post to this group, send email to google-c...@googlegroups.com. > To unsubscribe from this group, send email to > google-code+unsubscr...@googlegroups.com<google-code%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-code?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to google-c...@googlegroups.com. To unsubscribe from this group, send email to google-code+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.