fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string GetElDot(const string& Msg, int Where, int* WhereNext) {
  5. string outputStr;
  6.  
  7. int WhereDot = Msg.find('.', Where);
  8. int WhereBackSlash = Msg.find('/', Where);
  9.  
  10. // there is no . but there is / e.g. CQ330/WQ
  11. // OR there is . and there is / and dot is after / e.g. CQ330/WQ320.
  12. if ((WhereDot < 0 && WhereBackSlash >= 0) || (WhereDot >= 0 && WhereBackSlash >= 0 && WhereDot > WhereBackSlash)) {
  13. outputStr.assign(Msg, Where, WhereBackSlash - Where);
  14. (*WhereNext) = WhereBackSlash + 1;
  15. return outputStr;
  16. }
  17.  
  18. // there is no . and there is no / e.g. CQ330/WQ (Where=6)
  19. if (WhereDot < 0 && WhereBackSlash < 0) {
  20. outputStr.assign(Msg, Where, Msg.size() - Where);
  21. (*WhereNext) = Msg.size(); // end of string (there is no next element)
  22. return outputStr;
  23. }
  24.  
  25. // there is . and there is / and dot is before / e.g. CQ330.330/
  26. // or there is a dot but there is no / e.g. CQ234.345
  27. if ((WhereDot >= 0 && WhereBackSlash >= 0 && WhereDot < WhereBackSlash) || (WhereDot >= 0 && WhereBackSlash < 0)) {
  28. outputStr.assign(Msg, Where, WhereDot - Where);
  29. (*WhereNext) = WhereDot + 1;
  30. return outputStr;
  31. }
  32.  
  33. // error format
  34. (*WhereNext) = Msg.size(); // end of string (there is no next element)
  35.  
  36. return outputStr;
  37. }
  38.  
  39. int main() {
  40. // your code goes here
  41. std::string start = "PETAK.LOLEK";
  42. int whereNext = 0;
  43.  
  44. std::string out = GetElDot(start, 0, &whereNext);
  45.  
  46. cout << start << "=" << out << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
PETAK.LOLEK=PETAK