C语言:ACM大数运算问题.--------------------------------------------------------------------------------Time limit:1000MS Memory limit:32768K Total Submit:204 Accepted:71 -------------------------------------------------------------------------
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/06 04:04:02
C语言:ACM大数运算问题.--------------------------------------------------------------------------------Time limit:1000MS Memory limit:32768K Total Submit:204 Accepted:71 -------------------------------------------------------------------------
C语言:ACM大数运算问题.
--------------------------------------------------------------------------------
Time limit:1000MS Memory limit:32768K
Total Submit:204 Accepted:71
--------------------------------------------------------------------------------
一个数M是个非常大非常的大数,有多大呢?而众所周知,WT很可恶,他喜欢出很多难题让师兄弟们郁闷至.所以他今天对着这个M看了半天,经过吐血思考!他决定再给出一个N,N可以用一个32位的INT存下.然后让师兄弟们去算出M/N的整数部分,和M%N!愿上帝也憎恨可恶的WT!输入以文件结束为结束.
Sample Input
123456789012345678901234567890 100
Sample Output
1234567890123456789012345678 90
题目在上面.麻烦大神用C或C++写一下代码.
C语言:ACM大数运算问题.--------------------------------------------------------------------------------Time limit:1000MS Memory limit:32768K Total Submit:204 Accepted:71 -------------------------------------------------------------------------
c++代码如下
#include
using namespace std;
string s;
int d;
int main() {
while (cin >> s >> d) {//如果是只有一组测试数据就写成cin>>s>>d;
int cur = 0;
string ans;
for (int i = 0; i < s.length(); i++) {
cur = cur * 10 + s[i] - '0';
ans += (char) (cur / d + '0');
cur %= d;
}
bool flag = 0;
for (int i = 0; i < ans.length(); i++) {
if (ans[i] != '0') flag = 1;
if (flag) cout