Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<string> v;
- string int2string(int a)
- {
- stringstream ss;
- ss << a;
- string wynik = ss.str();
- return wynik;
- }
- int oct2dec(string s)
- {
- int n = s.length();
- int w = 0;
- for (int i = 0; i < n; i++)
- {
- w = w*8 + s[i] - '0';
- }
- return w;
- }
- bool rosnie(string s)
- {
- int n = s.length();
- for (int i=1; i<n; i++)
- {
- if (s[i] < s[i-1]) return false;
- }
- return true;
- }
- bool mniejsze(string a, string b)
- {
- if (a.size() == b.size())
- {
- int i = 0;
- while(a[i]==b[i])i++;
- return a[i] < b[i];
- }
- else return a.size() < b.size();
- }
- int main()
- {
- ifstream plik("dane.txt");
- ofstream wyniki("wyniki.txt");
- int l1 = 0, l2 = 0, l3 = 0;
- string o;
- for (int i=0; i<5000; i++)
- {
- plik >> o;
- // a
- if (o[0] == o[o.size()-1]) l1++;
- // b
- int dec = oct2dec(o);
- string d = int2string(dec);
- if (d[0] == d[d.size()-1]) l2++;
- // c
- if (rosnie(o)) {v.push_back(o); l3++;}
- }
- plik.close();
- wyniki << "a) " << l1 << endl;
- wyniki << "b) " << l2 << endl;
- wyniki << "c) " << l3 << endl;
- sort (v.begin(), v.end(), mniejsze);
- wyniki << "c) " << v.front() << endl; // v[0]
- wyniki << "c) " << v.back() << endl; // v[v.size()-1]
- cout << "Wyniki zapisano w pliku wyniki.txt" << endl;
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement