Advertisement
Valeri12580

Zadacha 2.1

Mar 5th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1.  
  2. //
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8. struct TS{
  9. string str;
  10. double w;
  11. char ch;
  12. };
  13.  
  14.  
  15.  
  16. void zadachaEdno(TS &object,string criteria) {
  17. string firstCut = object.str.substr(0,criteria.length());
  18. string lastCut = object.str.substr(object.str.length()-criteria.length());
  19.  
  20. if (firstCut.compare(criteria)==0 && lastCut.compare(criteria)==0) {
  21.  
  22.  
  23. string newStr;
  24. double newW;
  25. int firstChar;
  26.  
  27. do {
  28. cout << "Vuvedi new Str:" << endl;
  29. cin >> newStr;
  30.  
  31. cout << "Vuvedi new W:" << endl;
  32. cin >> newW;
  33.  
  34. firstChar = newStr.find_first_of(object.ch);
  35. } while (newW<object.w || firstChar ==string::npos || newStr.find_first_of(object.ch,firstChar)==string::npos );
  36.  
  37. object.str = newStr;
  38. object.w = newW;
  39.  
  40.  
  41. }
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. TS object = { "rileri",15,'a' };
  48. string criteria;
  49.  
  50. cout << "Enter criteria:" << endl;
  51. cin >> criteria;
  52. zadachaEdno(object,criteria);
  53. cout << object.str << " " << object.w << endl;
  54. system("pause");
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement