-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
48 lines (36 loc) · 815 Bytes
/
solution.cpp
File metadata and controls
48 lines (36 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<vector>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;
int main(){
string num;
vector<unsigned long long int> bin;
cout << "Enter a num string: ";
getline(cin, num);
unsigned long long int number = stoi(num);
while(number>0){
int lastDigit = number % 10;
bin.push_back(lastDigit);
number = number / 10;
}
reverse(bin.begin(), bin.end());
for (int i = 0; i < bin.size(); i++)
{
if(bin[i]<5){
bin[i]=0;
}
else{
bin[i]=1;
}
}
ostringstream oss;
string str;
for (int num : bin) {
oss << num;
}
str = oss.str();
cout << "Отриманий рядок: " << str << endl;
return 0;
}