Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- char input[300];
- cin.getline(input, 300);
- char firstNumber[100];
- int a = 2;
- while (input[a]!=' ')
- {
- firstNumber[a - 2] = input[a];
- a++;
- }
- int b = 0;
- firstNumber[a-2] = '\0';
- char secondNumber[100];
- while (input[a] != '\0')
- {
- secondNumber[b] = input[a];
- b++;
- a++;
- }
- secondNumber[b] = '\0';
- int counter1 = 0;
- while (firstNumber[counter1] != '\0')
- {
- counter1++;
- }
- int counter2 = 0;
- while (secondNumber[counter2] != '\0')
- {
- counter2++;
- }
- int arr1[100];
- int arr2[100];
- for (int i = 0; i < 100; i++)
- {
- arr1[i] = 0;
- arr2[i] = 0;
- }
- for (int i = 0; i < counter1; i++)
- {
- arr1[99 - i] = firstNumber[counter1 - i - 1] - '0';
- }
- for (int i = 0; i < counter2; i++)
- {
- arr2[99 - i] = secondNumber[counter2 - i - 1] - '0';
- }
- char operation=input[0];
- int result[300];
- for (int i = 0; i < 300; i++)
- {
- result[i] = 0;
- }
- if (operation == '+') {
- int max = 0;
- if (counter1 > counter2)
- {
- max = counter1;
- }
- else
- {
- max = counter2;
- }
- int temp = 0;
- int i = 99;
- for (; i > 99 - max; i--)
- {
- int a = arr1[i] + arr2[i] + temp;
- temp = a / 10;
- result[i] = a % 10;
- }
- if (temp != 0)
- {
- result[i] = temp;
- }
- }
- else if (operation == '-')
- {
- if (counter1 == counter1)
- {
- int temp = 0;
- int i = 99;
- for (; i > 99 - counter1; i--)
- {
- if ((arr1[i] - arr2[i]) < 0)
- {
- int tempI = i - 1;
- if (arr1[tempI] == 0)
- {
- while (arr1[i] == 0)
- {
- i--;
- }
- arr1[tempI]--;
- while (i - 1 != tempI)
- {
- tempI++;
- arr1[tempI] = 9;
- }
- result[i] = arr1[i] + 10 - arr2[i];
- }
- else
- {
- arr1[tempI]--;
- result[i] = arr1[i] + 10 - arr2[i];
- }
- }
- else
- {
- result[i] = arr1[i] - arr2[i];
- }
- }
- }
- else if (counter1 > counter2)
- {
- int temp = 0;
- int i = 99;
- for (; i > 99 - counter1; i--)
- {
- if (true)
- {
- if ((arr1[i] - arr2[i]) < 0)
- {
- int tempI = i - 1;
- if (arr1[tempI] == 0)
- {
- while (arr1[i] == 0)
- {
- i--;
- }
- arr1[tempI]--;
- while (i - 1 != tempI)
- {
- tempI++;
- arr1[tempI] = 9;
- }
- result[i] = arr1[i] + 10 - arr2[i];
- }
- else
- {
- arr1[tempI]--;
- result[i] = arr1[i] + 10 - arr2[i];
- }
- }
- else
- {
- result[i] = arr1[i] - arr2[i];
- }
- }
- else
- {
- result[i] = arr1[i];
- }
- }
- }
- else
- {
- int temp = 0;
- int i = 99;
- for (; i > 99 - counter2; i--)
- {
- if (true)
- {
- if ((arr2[i] - arr1[i]) < 0)
- {
- int tempI = i - 1;
- if (arr2[tempI] == 0)
- {
- while (arr2[i] == 0)
- {
- i--;
- }
- arr2[tempI]--;
- while (i - 1 != tempI)
- {
- tempI++;
- arr2[tempI] = 9;
- }
- result[i] = arr2[i] + 10 - arr1[i];
- }
- else
- {
- arr2[tempI]--;
- result[i] = arr2[i] + 10 - arr1[i];
- }
- }
- else
- {
- result[i] = arr2[i] - arr1[i];
- }
- }
- else
- {
- result[i] = arr2[i];
- }
- }
- }
- }
- else if (operation == '*')
- {
- int max = 0;
- int min = 0;
- int biggerOne = 0;
- if (counter1 > counter2)
- {
- max = counter1;
- min = counter2;
- biggerOne = 1;
- }
- else
- {
- min = counter1;
- max = counter2;
- biggerOne = 2;
- }
- int temp = 0;
- int tempArr2[300];
- int tempArr1[300];
- for (int i = 0; i < 300; i++)
- {
- tempArr1[i] = 0;
- }
- int i = 99;
- for (; i > 99 - max; i--)
- {
- for (int i = 0; i < 300; i++)
- {
- tempArr2[i] = 0;
- }
- if (biggerOne==1)
- {
- for (int j = 299; j > 299-(i-99); j--)
- {
- tempArr2[j] = 0;
- }
- int j = 299;
- for (; j > 299-min; j--)
- {
- int a = arr1[i] * arr2[j-200] + temp;
- temp = a / 10;
- tempArr2[j-(99-i)] = a % 10;
- }
- if (temp!=0)
- {
- tempArr2[j - (99 - i)]=temp;
- }
- }
- else
- {
- for (int j = 99; j < i - 99; j++)
- {
- tempArr2[j] = 0;
- }
- for (int j = 99 - min; j < 99; j++)
- {
- int a = arr1[i] * arr2[j] + temp;
- temp = a / 10;
- tempArr2[j + i] = a % 10;
- }
- }
- for (int i = 0; i < 300; i++)
- {
- tempArr1[i] = result[i];
- }
- int tempN = 0;
- for (int i=299; i > 0; i--)
- {
- int a = tempArr1[i] + tempArr2[i] + tempN;
- tempN = a / 10;
- result[i] = a % 10;
- }
- }
- }
- for (int i = 0; i < 300; i++)
- {
- if (result[i] >= 0 && result[i] <= 9)
- {
- cout << result[i];
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement