Posts

Showing posts from November, 2015

UVA 713 - Adding Reversed Numbers Solution

UVA 713 - Adding Reversed Numbers Solution   '0'+'0'=96    (48+48) 48 is the ASCII value of zero. Sum of two char  is 96 is means 0. Sum value 97 means 1..... Sum value 105 means 9. Sum value 106 means 10. So, result is 0 and carry is 1. which add to next chars sum. CODE: #include<iostream> #include<map> #include<algorithm> #include<string> using namespace std; int trailZero(string str) {      int index=0;      while(str[index]=='0')      {         index++;      }      return index; } int main() {     map<char,char> charToInt;     string s1,s2,s3;     char ch;     int i,len1,len2,max_len,carry,test;     for(i=0;i<10;i++)         charToInt[i+96]=i+48;     cin>>te...

UVA 713 Adding Reversed Numbers Solution

UVA 713 Adding Reversed Numbers Solution /*uva id: shoaib05    Accepted Time: 0.000 */ Procedure: Take input as string. Reverse the string. build the string equal length by putting zeros at start. Split the string and store in queue. Input: 8000000001   length is 10 1000101         length is 7 max_length is 10. Reverse the string 1000000008                                     1010001 put zero and build equal length. 0001010001 str1 is 1000000008 str2 is 0001010001 Here I spilt the string by size 4 and store in queue. Queue 1 0008 0000 rest of digits store in rem1=10 Queue 2 0001 0101 rest of digits store in rem2=00 Take string from queue1 and queue2, convert srings to number and add. If size exceed max size of 4 digit 9999 then subtract the sum value from 10000. put the subtract's value i...