Created
March 12, 2015 22:13
-
-
Save hpetru/e07c72c3d79f87a324ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 3 | |
| 100 | |
| 1 | |
| 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| #include <bitset> | |
| #include <fstream> | |
| class bitn : public std::bitset<16> | |
| { | |
| public: | |
| bitn() : std::bitset<16>() {} | |
| bitn(int x) : std::bitset<16>(x) {} | |
| bitn(long unsigned int x) : std::bitset<16>(x) {} | |
| bitn(std::string s) : std::bitset<16>(s) {} | |
| friend bitn operator + (bitn lth, bitn rth); | |
| friend bitn operator - (bitn lth, bitn rth); | |
| friend bitn operator / (bitn lth, bitn rth); | |
| friend bitn operator * (bitn lth, bitn rth); | |
| friend bool operator > (bitn lth, bitn rth); | |
| friend bool operator < (bitn lth, bitn rth); | |
| }; | |
| bitn operator + (bitn lth, bitn rth) | |
| { | |
| bitn result((int)(lth.to_ulong() + rth.to_ulong())); | |
| return result; | |
| } | |
| bitn operator - (bitn lth, bitn rth) | |
| { | |
| bitn result((int)(lth.to_ulong() - rth.to_ulong())); | |
| return result; | |
| } | |
| bitn operator / (bitn lth, bitn rth) | |
| { | |
| bitn result((int)(lth.to_ulong() / rth.to_ulong())); | |
| return result; | |
| } | |
| bitn operator * (bitn lth, bitn rth) | |
| { | |
| bitn result((int)(lth.to_ulong() * rth.to_ulong())); | |
| return result; | |
| } | |
| bool operator > (bitn lth, bitn rth) | |
| { | |
| return (lth.to_ulong() > rth.to_ulong()); | |
| } | |
| bool operator < (bitn lth, bitn rth) | |
| { | |
| return (lth.to_ulong() < rth.to_ulong()); | |
| } | |
| int main() | |
| { | |
| bitn bs[10]; | |
| int n = 0; | |
| std::ifstream in("./binary.in"); | |
| in >> n; | |
| for(int i = 0; i < n; i++) | |
| { | |
| std::string buff; | |
| in >> buff; | |
| bs[i] = bitn(buff); | |
| } | |
| bitn max; | |
| max = bs[0]; | |
| for(int i = 0; i < n; i++) | |
| { | |
| if(bs[i] > max) max = bs[i]; | |
| } | |
| std::cout << "Numarul maxim este: \t" << max << std::endl; | |
| std::cout << "Valoare lui zecimala: \t" << max.to_ulong() << std::endl; | |
| unsigned int sum; | |
| for(int i = 0; i < n; i++) | |
| { | |
| sum += bs[i].to_ulong(); | |
| } | |
| std::cout << "Suma este: \t"; | |
| std::cout << sum << std::endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment