-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path29.cpp
More file actions
executable file
·36 lines (32 loc) · 780 Bytes
/
29.cpp
File metadata and controls
executable file
·36 lines (32 loc) · 780 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
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
class Solution {
public:
int divide(int dividend, int divisor) {
int flag = 1;
int answer = 0;
if (dividend == 0) return 0;
double tmp = dividend;
if (divisor < 0){
flag = -1;
divisor = -divisor;
if (dividend < 0){
flag = 1;
tmp = double(dividend);
tmp = tmp * - 1;
}
} else {
if (dividend < 0){
flag = -1;
tmp = double(dividend);
tmp = tmp * - 1;
}
}
while (tmp >= divisor) {
tmp -= divisor;
answer ++;
}
return flag * answer;
}
};