这道题和之前三道高精度的题一起挂的吧,但是隔了两天才来把它给AC了,刚开始还是想的太复杂了吧,认为是两个大数的除法,但是这道题当中分母是一个在int可接受范围内的数,那么这个问题就变得很简单了,没有太多好说的,只要模拟一下除法的步骤就可以了
原本打算用这题作为高精度运算初步的收关题的,看样子还是简单了
代码如下:
Result : Accepted Memory : 0 KB Time : 9 ms
/* * Author: Gatevin * Created Time: 2014/7/5 22:52:20 * File Name: test.cpp */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue> #include<stack> #include<map> #include<set> #include<bitset> #include<algorithm> #include<cstdio> #include<cstdlib> #include<cstring> #include<cctype> #include<cmath> #include<ctime> #include<iomanip> using namespace std; const double eps(1e-8); typedef long long lint; void Div(string s, long long den) { long long num = 0;//用num储存要背除的数 int fro = 0; string ans; while(fro < s.length()) { num = num*10 + (s[fro] - '0'); ans += (char)(num/den + '0');//每次出之后的商存在ans里 num %= den; fro++; } int sta = 0; while(ans[sta] == '0' && sta < s.length() - 1)//输出忽略前导零 { sta++; } for(int i = sta; i < ans.length(); i++) { cout<<ans[i]; } cout<<endl; return; } void Mod(string s, long long den)//有了之前商的做法,取模运算也就不再话下 { long long num = 0; int fro = 0; while(fro < s.length()) { num = num*10 + (s[fro] - '0'); num %= den; fro++; } cout<<num<<endl; } int main() { string s0; long long n; char op; while(cin>>s0>>op>>n) { switch(op) { case '/': Div(s0, n); break; case '%': Mod(s0, n); break; } } return 0; }