Advertisement
Valeri12580

zadacha 2.2

Mar 5th, 2020
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 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. double zadachaDve(TS objects[],int length) {
  17. double average = 0;
  18.  
  19. int count = 0;
  20.  
  21. string numbers = "0123456789";
  22. for (int i = 0; i < length; i++)
  23. {
  24. TS currentObject = objects[i];
  25. if (currentObject.str.find_first_of(numbers)==string::npos && numbers.find_first_of(currentObject.ch)!=string::npos) {
  26. cout << currentObject.str << endl;
  27. average += currentObject.w;
  28. count++;
  29. }
  30.  
  31. }
  32.  
  33. if (count == 0) {
  34. return -1;
  35. }
  36.  
  37. return average / count;
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43. TS objects[] = { "riledri",15,'a' ,
  44. "nark3213oman",15,'57' ,
  45. "bokKiro",5,'10' ,
  46. "daskircata",15,'a' ,
  47. };
  48.  
  49. cout << zadachaDve(objects, 4) << endl;
  50.  
  51. system("pause");
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement