Advertisement
helenrut

Untitled

Oct 2nd, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string a, b, words; // Skilgreina strengina sem ég þarf að nota.
  9. unsigned int pos = 0;
  10. cin >> a >> b; // Orðin, sem breyturnar a og b.
  11.  
  12. getline(cin,words);
  13. pos = words.find(a);
  14.  
  15. for (unsigned int i = 0; i < words.length(); i++)
  16. {
  17. if (pos < words.length())
  18. {
  19. if (i == 0)
  20. {
  21. words.erase(pos, a.length());
  22. words.insert(pos, b);
  23. pos = words.find(a, pos + a.length());
  24. }
  25. else
  26. {
  27. words.erase(pos, a.length());
  28. words.insert(pos, b);
  29. pos = words.find(a, pos + a.length());
  30. }
  31.  
  32. {
  33.  
  34. pos = words.find_first_of(" ");
  35. while (pos < (words.length()-1))
  36. {
  37. if(isalpha(words[pos+1]))
  38. {
  39. words[pos+1] = toupper(words[pos + 1]);
  40. }
  41. pos = words.find_first_of(" ", pos + 1);
  42. }
  43.  
  44. }
  45. cout << words << endl;
  46. }
  47. return 0;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement