Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct weapon {
  8. string fim;
  9. string date;
  10. string type;
  11. int price;
  12. };
  13.  
  14. int main() {
  15. setlocale(LC_ALL, "rus");
  16. int symb = -1; int zpt = -1;
  17.  
  18. ifstream f("C:\\Users\\User\\Documents\\Visual Studio 2010\\Projects\\SafrSafr2\\doc.txt");
  19. if (!f.is_open()) {
  20. cout << "Файл не открыт!";
  21. }
  22. while (!f.eof())
  23. {
  24. char temp;
  25. f >> temp;
  26. if (temp == ',')zpt++;
  27. symb++;
  28. }
  29.  
  30. char *mas = new char[symb];
  31.  
  32. f.clear();
  33. f.seekg(0);
  34. for (int i = 0; i<symb; i++) {
  35. f >> mas[i];
  36. }
  37. f.close();
  38.  
  39.  
  40. weapon *wp = new weapon[zpt];
  41. string* arr = new string[zpt * 4];
  42. char *tok = strtok(mas, ",");
  43. int i = 0;
  44. while (tok)
  45. {
  46. arr[i] = tok;
  47. tok = strtok(NULL, ",");
  48. i++;
  49. }
  50.  
  51. for(int i=0,j=0;i<zpt;i++,j+=4){
  52. wp[i].fim = arr[j];
  53. wp[i].date = arr[j+1];
  54. wp[i].type = arr[j+2];
  55. wp[i].price = stoi(arr[j+3]);
  56. }
  57.  
  58. for(int i = 0;i<zpt;i++){
  59. for(int j = 0;j<zpt-i-1;j++){
  60. if(wp[j].price<wp[j+1].price){
  61. swap(wp[j].price,wp[j+1].price);
  62. }
  63. }
  64. }
  65. for (int i = 0; i<zpt/4; i++)
  66. {
  67. cout << wp[i].price<<endl;;
  68. }
  69.  
  70. system("pause");
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement