Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct weapon {
- string fim;
- string date;
- string type;
- int price;
- };
- int main() {
- setlocale(LC_ALL, "rus");
- int symb = -1; int zpt = -1;
- ifstream f("C:\\Users\\User\\Documents\\Visual Studio 2010\\Projects\\SafrSafr2\\doc.txt");
- if (!f.is_open()) {
- cout << "Файл не открыт!";
- }
- while (!f.eof())
- {
- char temp;
- f >> temp;
- if (temp == ',')zpt++;
- symb++;
- }
- char *mas = new char[symb];
- f.clear();
- f.seekg(0);
- for (int i = 0; i<symb; i++) {
- f >> mas[i];
- }
- f.close();
- weapon *wp = new weapon[zpt];
- string* arr = new string[zpt * 4];
- char *tok = strtok(mas, ",");
- int i = 0;
- while (tok)
- {
- arr[i] = tok;
- tok = strtok(NULL, ",");
- i++;
- }
- for(int i=0,j=0;i<zpt;i++,j+=4){
- wp[i].fim = arr[j];
- wp[i].date = arr[j+1];
- wp[i].type = arr[j+2];
- wp[i].price = stoi(arr[j+3]);
- }
- for(int i = 0;i<zpt;i++){
- for(int j = 0;j<zpt-i-1;j++){
- if(wp[j].price<wp[j+1].price){
- swap(wp[j].price,wp[j+1].price);
- }
- }
- }
- for (int i = 0; i<zpt/4; i++)
- {
- cout << wp[i].price<<endl;;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement