LeetCode-29-两数相除
/*两数相除*/
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int dd, ds;//dd是被除数,ds是除数
long long res, s;//s为商
int flag = 0;//判断正负
cin >> dd >> ds;
if (ds == 0){//除数不可以为0
return 0;
}
else{
if ((dd >= 0 && ds > 0) || (dd < 0 && ds < 0)){
flag = 1;//正号
}
res = abs(dd);//取绝对值
ds = abs(ds);
s = 0;
if (res == 0){
s = 1;
}
while (res > 0){
res = res - ds;
s++;
}
}
if (flag == 0){
cout << '-';
}
long long tmp = s - 1;
if (tmp > INT_MAX || tmp < INT_MIN){
cout << INT_MAX << endl;
}
else{
cout << tmp << endl;
}
return 0;
}