Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Help] Task problem - C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Sat Nov 29, 2008 8:37 am    Post subject: [Help] Task problem - C++ Reply with quote

I'm currently doing a task which has this text:
Quote:

Task A3: String
The problem statement now reads
"Write a program string, which splits a given string in a concatenation of simple substrings, such that each substring (but the first) is lexicographically smaller than or equal to the previous one."


Actually I can't fully understand what the task asks, from what I get it gives you a string using the standard input and then you have to order alphabetically the substrings.
But I don't get how should the string be splitted (seems the delimiter isn't space) Confused
This is my code
Code:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

bool str_tok(std::string str, std::string& ret, const char* delim)
{
   size_t n = str.find(delim);
   ret = str.substr(0, n);

   if(n == std::string::npos)
      return false;
   else
      return true;
}

bool lessLexCompare (const std::string& l1, const std::string& l2)
{
    return !lexicographical_compare(l1.begin(), l1.end(), l2.begin(), l2.end());
}

int main (int argc, char** argv)
{
   std::string str;
   std::string sub;
   std::vector<std::string> v;
   size_t n = 0;
   bool next;

   std::getline(std::cin, str);

   do
   {
      next = str_tok(str.c_str() + n, sub, " ");
      v.push_back(sub);
      n += sub.size() + 1;
   } while (next);

   std::sort(v.begin(), v.end(), lessLexCompare);

   for(size_t i = 0; i < v.size(); ++i)
   {
      std::cout << v[i] << std::endl;
   }
   return 0;
}

And actually the result says so
Quote:

[16:27:14] string
[HEADER CHECK - OK]
task : string
language : C++
[COMPILE - OK]
compile time : 1.86 seconds
[SAMPLE DATA TEST - ERROR !!!]
execution time : 0.00 seconds
--[correct answer]-----------
4 1 3 5 1


--[your answer]--------------
baabaaabba <---------- This is the given input string


--[checker message]----------
Wrong answer
Wrong line 0


Actually, how should it be done?

_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites