Advertisement
Guest User

dave

a guest
Mar 28th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | None | 0 0
  1.     string resultatenbinaire = ""; mais changez le nom des variables pour pas que ce soit cramé qu'on ait la même chose
  2.     string resultatenmorse = ""; svp
  3.     string resultatenlettres = "";
  4.  
  5.  
  6.  
  7.  
  8. resultatenmorse = resultatenbinaire;
  9.    
  10.     for (g = 0; g < resultatenmorse.size();g++) { //This loop finds corresponding morse characters to binary digits sequences
  11.         if (resultatenmorse.substr(g, 3) == "111") {
  12.             resultatenmorse.replace(resultatenmorse.find("111"),3, "-" );
  13.         }
  14.         else if(resultatenmorse.substr(g, 1) == "1"){
  15.             resultatenmorse.replace(resultatenmorse.find("1"), 1, ".");
  16.         }
  17.         else if (resultatenmorse.substr(g, 7) == "0000000") {
  18.             resultatenmorse.replace(resultatenmorse.find("0000000"), 7, " / ");
  19.         }
  20.         else if (resultatenmorse.substr(g, 3) == "000") {
  21.             resultatenmorse.replace(resultatenmorse.find("000"), 3, " ");
  22.         }
  23.     }
  24.  
  25.  
  26.     for (g = 0; g < resultatenmorse.size();g++) {
  27.         if (resultatenmorse.substr(g, 1) == "0") {
  28.             resultatenmorse.replace(resultatenmorse.find("0"), 1, "");
  29.         }
  30.     }
  31.  
  32.     cout << "\n" << "l'équivalent en morse est : " << resultatenmorse;
  33.    
  34.     resultatenlettres = resultatenmorse;
  35.  
  36.     for (g = 0; g < resultatenlettres.size(); g++) {
  37.         if (resultatenlettres.substr(g, 5) == "...--") {
  38.             resultatenlettres.replace(resultatenlettres.find("...--"), 5, "3");
  39.         }
  40.         else if (resultatenlettres.substr(g, 5) == ".----") {
  41.             resultatenlettres.replace(resultatenlettres.find(".----"), 5, "1");
  42.         }
  43.         else if (resultatenlettres.substr(g, 4) == ".-..") {
  44.             resultatenlettres.replace(resultatenlettres.find(".-.."), 4, "L");
  45.         }
  46.         else if (resultatenlettres.substr(g, 4) == "-..-") {
  47.             resultatenlettres.replace(resultatenlettres.find("-..-"), 4, "X");
  48.         }
  49.         else if (resultatenlettres.substr(g, 4) == "....") {
  50.             resultatenlettres.replace(resultatenlettres.find("...."), 4, "H");
  51.         }
  52.         else if (resultatenlettres.substr(g, 4) == "-...") {
  53.             resultatenlettres.replace(resultatenlettres.find("-..."), 4, "B");
  54.         }
  55.         else if (resultatenlettres.substr(g, 4) == "-.--") {
  56.             resultatenlettres.replace(resultatenlettres.find("-.--"), 4, "Y");
  57.         }
  58.         else if (resultatenlettres.substr(g, 4) == ".---") {
  59.             resultatenlettres.replace(resultatenlettres.find(".---"), 4, "J");
  60.         }
  61.         else if (resultatenlettres.substr(g, 4) == "-.-.") {
  62.             resultatenlettres.replace(resultatenlettres.find("-.-."), 4, "C");
  63.         }
  64.         else if (resultatenlettres.substr(g, 3) == "..-") {
  65.             resultatenlettres.replace(resultatenlettres.find("..-"), 3, "U");
  66.         }
  67.         else if (resultatenlettres.substr(g, 3) == "---") {
  68.             resultatenlettres.replace(resultatenlettres.find("---"), 3, "O");
  69.         }
  70.         else if (resultatenlettres.substr(g, 3) == ".-.") {
  71.             resultatenlettres.replace(resultatenlettres.find(".-."), 3, "R");
  72.         }
  73.         else if (resultatenlettres.substr(g, 3) == ".--") {
  74.             resultatenlettres.replace(resultatenlettres.find(".--"), 3, "W");
  75.         }
  76.         else if (resultatenlettres.substr(g, 3) == "...") {
  77.             resultatenlettres.replace(resultatenlettres.find("..."), 3, "S");
  78.         }
  79.         else if (resultatenlettres.substr(g, 2) == "..") {
  80.             resultatenlettres.replace(resultatenlettres.find(".."), 2, "I");
  81.         }
  82.         else if (resultatenlettres.substr(g, 1) == ".") {
  83.             resultatenlettres.replace(resultatenlettres.find("."), 1, "E");
  84.         }
  85.         else if (resultatenlettres.substr(g, 1) == "-") {
  86.             resultatenlettres.replace(resultatenlettres.find("-"), 1, "T");
  87.         }
  88.     }
  89.  
  90.     for (g = 0; g < resultatenlettres.size(); g++) {
  91.         if (resultatenlettres.substr(g, 3) == "/ ") {
  92.             resultatenlettres.replace(resultatenlettres.find("/ "), 2, "");
  93.         }
  94.         else if (resultatenlettres.substr(g, 1) == " ") {
  95.             resultatenlettres.replace(resultatenlettres.find(" "), 1, "");
  96.         }
  97.     }
  98.  
  99.     for (g = 0; g < resultatenlettres.size(); g++) {
  100.         if (resultatenlettres.substr(g, 1) == "/") {
  101.             resultatenlettres.replace(resultatenlettres.find("/"), 1, " ");
  102.         }
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement