hdu Big Number

简单题

Problem Description
As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B.

To make the problem easier, I promise that B will be smaller than 100000.

Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.


Input
The input contains several test cases. Each test case consists of two positive integers A and B. The length of A will not exceed 1000, and B will be smaller than 100000. Process to the end of file.


Output
For each test case, you have to ouput the result of A mod B.


Sample Input
2 3
12 7
152455856554521 3250


Sample Output
2
5
1521

代码:

#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring> 
#include <stdio.h>
#include <iomanip> 
using namespace std;
int cmp(char c)
{
	if(c=='0') return 0;
	else if(c=='1') return 1;
	else if(c=='2') return 2;
	else if(c=='3') return 3;
	else if(c=='4') return 4;
	else if(c=='5') return 5;
	else if(c=='6') return 6;
	else if(c=='7') return 7;
	else if(c=='8') return 8;
	else if(c=='9') return 9;
	
}
int main()
{
	string st;
	int n,sum;
	while(cin>>st>>n)
	{   sum=0;
		for(int i=0;i<st.size();i++)
		{
			sum=sum*10+cmp(st[i]);
			sum=sum%n;
		}
		cout<<sum<<endl;
	}
	return 0;
}


posted @ 2015-12-08 11:01  (慎独)  阅读(155)  评论(0编辑  收藏  举报