vivienneanthony

Testing declustering code

Aug 27th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. /// string test
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. void mapdatatogrid(string mapdata);
  9.  
  10. int main()
  11. {
  12.     /// define map
  13.     string mapdata;
  14.  
  15.     /// append map
  16.     mapdata.append("!-6:-4:A:3:3!2:-4:A:3:3!-6:-4:A:3:3!-6:-4:A:3:3");
  17.  
  18.     mapdatatogrid(mapdata);
  19.  
  20.  
  21.     return 0;
  22. }
  23.  
  24.  
  25. void mapdatatogrid(string mapdata)
  26. {
  27.     unsigned int findfirstcluster;
  28.     unsigned int findclusterend;
  29.  
  30.     bool decluster = true;
  31.  
  32.     /// find first cluster
  33.     findfirstcluster=findfirstcluster = mapdata.find("!");
  34.  
  35.     /// check clusting
  36.     do
  37.     {
  38.         /// test first cluser
  39.         if(findfirstcluster!=string::npos||findfirstcluster==0)
  40.         {
  41.             /// find the cluster end
  42.             findclusterend=mapdata.find("!",findfirstcluster+1);
  43.  
  44.             if(findclusterend==0||findclusterend==string::npos)
  45.             {
  46.                 decluster=false;
  47.  
  48.                 cout << "break";
  49.                 break;
  50.             }
  51.             else
  52.             {
  53.                 string newstring = mapdata.substr(findfirstcluster+1,(unsigned int)findclusterend-(findfirstcluster+1));
  54.  
  55.                 cout << newstring.c_str() << endl;
  56.  
  57.                 findfirstcluster = mapdata.find("!",findfirstcluster+1);
  58.             }
  59.         }
  60.     }
  61.     while(decluster==true);
  62.  
  63.     return;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment