-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
41 lines (34 loc) · 776 Bytes
/
solution.cpp
File metadata and controls
41 lines (34 loc) · 776 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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
extern "C" {
#include <math.h>
}
using namespace std;
vector<char> seprated(long num) {
string str = to_string(num);
reverse(str.begin(), str.end());
int ccounter = 0;
vector<char> vect;
for(char c : str) {
vect.push_back(c);
ccounter++;
if(ccounter % 3 == 0 && ccounter < str.length()) {
vect.push_back(',');
}
}
reverse(vect.begin(), vect.end());
return vect;
}
int main(void) {
long num1, num2;
cin >> num1 >> num2;
long sum = num1 + num2;
int flag = sum < 0 ? 1 : 0;
auto res = seprated(abs(sum));
cout << (flag == 1 ? "-" : "");
for(char c : res) {
cout << c;
}
}