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 1545. Hieroglyphs

why I have runtime eror on test 1?
Posted by nick nikuradze 23 Apr 2016 18:25
This is my code!!!
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 vector <string> str;
 vector <string> str1;
int main()
{
    char k;
 string s;
 vector <string> str;
 vector <string> str1;
 int n;
 cin>>n;
 for(int i=0; i<n; i++)
 {
     cin>>s;
     str.push_back(s);
 }
 cin>>k;

 for(int i=0; i<n; i++)
 {
     if(str[i][0]==k) str1.push_back(str[i]);
 }

 sort(str1.begin(),str1.end());
 for(int i=0; i<str.size(); i++)
 {
     cout<<str1[i]<<endl;
 }
 return 0;
}
Re: why I have runtime eror on test 1?
Posted by ToadMonster 23 Apr 2016 19:57
Do you check your code locally, using some C++ IDE or compiler? Why no? You MUST try.

You can, using VS or QTCreator:
- run task sample using debugger;
- catch "vector index out of range" exception/failure;
- fix it.

Edited by author 23.04.2016 20:06
Re: why I have runtime eror on test 1?
Posted by nick nikuradze 23 Apr 2016 20:54
I check it on c++ compiler and it do right
Re: why I have runtime eror on test 1?
Posted by nick nikuradze 23 Apr 2016 20:54
I check it on c++ compiler and it do right
Re: why I have runtime eror on test 1?
Posted by ToadMonster 23 Apr 2016 22:50
You definitely didn't check.

Your code contains mistakes. Your code must fail with some "vector index out of range" error when you run it locally in debug mode.

Probably you use "checked" in meaning "compiled without errors". It is wrong meaning.