标签:包括 include data stream 计算 nbsp div clu ace
1 #include<iostream> 2 #include<string> 3 4 using namespace std; 5 6 #define max(a,b) (a > b ? a : b) 7 8 void add(string longString, string shortString, int* num3) 9 { 10 int k = -1; 11 int longLen = longString.size(); 12 int shortLen = shortString.size(); 13 14 for (int i = 1; i <= longLen; i++) 15 { 16 num3[i] = longString[longLen - i] - 48; 17 } 18 for (int i = 1; i <= shortLen; i++) 19 { 20 num3[i] += shortString[shortLen - i] - 48; 21 } 22 } 23 24 int main() 25 { 26 string num1; 27 string num2; 28 int *num3 = new int[102]; 29 int k = -1; 30 31 cin >> num1; 32 cin >> num2; 33 34 if (num1.size() >= num2.size()) //如果1长1作为长字符串 35 { 36 add(num1, num2, num3); 37 } 38 else 39 { 40 add(num2, num1, num3); //如果2长2作为长字符串 41 } 42 43 int m = max(num1.size(), num2.size()); 44 for (int i = 1; i <= m; i++) 45 { 46 if (num3[i] >= 10) 47 { 48 num3[i] -= 10; 49 ++num3[i + 1]; 50 } 51 } 52 53 if (num3[m + 1] > 0) 54 { 55 m++; 56 } 57 58 59 for (int i = m; i >= 1; i--) 60 { 61 cout << num3[i]; 62 } 63 64 return 0; 65 }
标签:包括 include data stream 计算 nbsp div clu ace
原文地址:https://www.cnblogs.com/ZhengLijie/p/12696017.html