12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /* Wurst is the best. Create a function that takes a string and
- replaces every mention of any type of sausage with the German
- word "Wurst," unless—of course—the sausage is already a type of
- German "Wurst" (i.e. "Bratwurst", see below),
- then leave the sausage name unchanged
- *
- * | German Wursts | Convert to Wurst |
- * | ------------------ | ------------------ |
- * | Bratwurst | Kielbasa |
- * | Kochwurst | Chorizo |
- * | Leberwurst | Moronga |
- * | Mettwurst | Salami |
- * | Rostbratwurst | Sausage |
- * | ~ | Andouille |
- * | ~ | Naem |
- * | ~ | Merguez |
- * | ~ | Gurka |
- * | ~ | Snorkers |
- * | ~ | Pepperoni |
- * Append sausages from the "Convert to Wurst" column with "wurst".
- * Do not replace any German sausage with the word "Wurst".
- * The word "Wurst" must be title case.
- */
- std::string wurstIsBetter(std::string str) {
- std::vector<std::string> sausagelist = {"Kielbasa", "Chorizo", "Moronga",
- "Salami", "Sausage", "Andouille", "Naem", "Merguez",
- "Gurka", "Snorkers", "Pepperoni"};
- // loops through my sausagelist and replaces each element with WURST
- for(int i=0;i<sausagelist.size();i++){
- size_t beginWord = str.find(sausagelist[i]);
- // if not found, search for lowercase
- if(beginWord==std::string::npos){
- std::string temp = sausagelist[i];
- temp[0] = tolower(sausagelist[i][0]);
- beginWord = str.find(temp);
- }
- // if sausagelist[i] was found, replace it with "Wurst".
- if(beginWord!=std::string::npos){
- str.replace(beginWord,sausagelist[i].size(),std::string("Wurst"));
- // go back and check again
- i--;
- }
- }
- /*std::string hasWurst ("Wurst");
- // check the string to see if WURST is in it;no change.
- if(str.find(hasWurst)!=std::string::npos){
- // no change.
- }
- // if wurst is not found, replace "str" with WURST.
- else {
- str=str.replace(0,str.size(),"Wurst");
- }
- */
- return str;
- }
|