标签:bsp namespace 部分 queue 不为 ret style using int
#include<cstdio> #include<string.h> #include<iostream> #include<algorithm> #include<vector> #include<string> #include<queue> #include<map> #include<stack> using namespace std; string ans,a,b; ll atoi(string s) { int ans=0,t=1; for(int i=s.length()-1;i>=0;i--) { ans += (s[i]-‘0‘)*t; t *= 10; } return ans; } string itoa(long long num) { if(num == 0) return "0"; string ans; int h =0; while(num!=0) { int a = num%10; char ch = a+‘0‘; ans[h] = ch; h++; num /= 10; } for(int i=0,j=ans.length()-1;i<j;i++,j--) { int t; ans[i] = t; ans[i] = ans[j]; ans[j] = t; } return ans; } string div(string a,string b,int n) //a,b不为0 { string ta,ts = "",t="0000000000000000000"; int pos=0,al = a.length(),bl = b.length(); long long an,bn = atoi(b); int ct=0; while(1) { if(pos + bl - ts.length()<= al) //找出每次进行除法的两个数an,bn { ta = ts + a.substr(pos,bl-ts.length()); an = atoi(ta); pos += bl-ts.length(); if(an < bn) { if(pos == a.length()) //小数部分 { an = an * 10; //补0 } else { an = an*10 + (a[pos]-‘0‘); pos++; } } long long shang,yu; yu = an % bn; shang = an / bn; if(pos == a.length() && yu==0) { pos++; } if(yu == 0) ts=""; else ts = itoa(yu); } else { ta = ts + t.substr(0,bl - ts.length()); //a的整数部分用完了,补0 an = atoi(ta); f(an < bn) { an = an * 10; } long long shang,yu; yu = an % bn; shang = an / bn; if(yu == 0) break; else ts = itoa(yu); } } } int main() { int n; cin>>a>>b>>n; cout<<div(a,b,n); return 0; }
标签:bsp namespace 部分 queue 不为 ret style using int
原文地址:https://www.cnblogs.com/fzuhyj/p/10559280.html