sicily 1020 Big Integer

 大数取模,把输入的大数的字符串转换为整数,但同时每一步要取模(老是错在这里),不然就爆了int!
----> temp = ((temp * 10) + (s[i]-'0')) % a[j];
1
#include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <stack> 5 6 using namespace std; 7 8 int a[105]; 9 char s[505]; 10 11 int main() 12 { 13 int t; 14 cin >> t; 15 while(t--) 16 { 17 18 int n; 19 cin >> n; 20 if(n == 0) 21 { 22 cout << "(" << 0 << ")" << endl; 23 continue; 24 } 25 for(int i=0; i<n; i++) 26 cin >> a[i]; 27 28 cin >> s; 29 int len = strlen(s); 30 31 cout << "("; 32 for(int j=0; j<n; j++) 33 { 34 int temp=0; 35 for(int i=0; i<len; i++) 36 temp = ((temp * 10) + (s[i]-'0')) % a[j]; //每一步都要取模 37 38 if(n == 1) 39 cout << temp%a[j] << endl; 40 else 41 { 42 if(j == 0) 43 { 44 cout << temp%a[j]; 45 continue; 46 } 47 48 cout << "," << temp%a[j]; 49 50 } 51 } 52 cout << ")" << endl; 53 54 55 } 56 return 0; 57 }
原文地址:https://www.cnblogs.com/dominjune/p/4355545.html