|
|
вернуться в форум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; } 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 I check it on c++ compiler and it do right 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. I check it on c++ compiler and it do right |
|
|