Click here to Skip to main content
15,896,063 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to add tabs to CView Class? Pin
_Flaviu6-Mar-18 0:36
_Flaviu6-Mar-18 0:36 
GeneralRe: How to add tabs to CView Class? Pin
Sampath5796-Mar-18 0:45
Sampath5796-Mar-18 0:45 
GeneralRe: How to add tabs to CView Class? Pin
Sampath5796-Mar-18 20:18
Sampath5796-Mar-18 20:18 
GeneralRe: How to add tabs to CView Class? Pin
_Flaviu6-Mar-18 21:01
_Flaviu6-Mar-18 21:01 
GeneralRe: How to add tabs to CView Class? Pin
Sampath5796-Mar-18 21:20
Sampath5796-Mar-18 21:20 
GeneralRe: How to add tabs to CView Class? Pin
_Flaviu6-Mar-18 21:35
_Flaviu6-Mar-18 21:35 
GeneralRe: How to add tabs to CView Class? Pin
Sampath5796-Mar-18 21:51
Sampath5796-Mar-18 21:51 
GeneralRe: How to add tabs to CView Class? Pin
_Flaviu6-Mar-18 22:08
_Flaviu6-Mar-18 22:08 
GeneralRe: How to add tabs to CView Class? Pin
Sampath57910-Mar-18 22:15
Sampath57910-Mar-18 22:15 
GeneralRe: How to add tabs to CView Class? Pin
_Flaviu12-Mar-18 23:43
_Flaviu12-Mar-18 23:43 
QuestionSerializing CMapStringToPtr Pin
_Flaviu4-Mar-18 22:35
_Flaviu4-Mar-18 22:35 
AnswerRe: Serializing CMapStringToPtr Pin
CPallini4-Mar-18 23:29
mveCPallini4-Mar-18 23:29 
QuestionMSXML load - not able to read chinese characters in path Pin
Gopi Nath28-Feb-18 22:25
Gopi Nath28-Feb-18 22:25 
QuestionRe: MSXML load - not able to read chinese characters in path Pin
Richard MacCutchan28-Feb-18 22:52
mveRichard MacCutchan28-Feb-18 22:52 
AnswerRe: MSXML load - not able to read chinese characters in path Pin
Gopi Nath28-Feb-18 23:12
Gopi Nath28-Feb-18 23:12 
GeneralRe: MSXML load - not able to read chinese characters in path Pin
Richard MacCutchan28-Feb-18 23:15
mveRichard MacCutchan28-Feb-18 23:15 
GeneralRe: MSXML load - not able to read chinese characters in path Pin
Gopi Nath28-Feb-18 23:46
Gopi Nath28-Feb-18 23:46 
QuestionRe: MSXML load - not able to read chinese characters in path Pin
David Crow1-Mar-18 7:26
David Crow1-Mar-18 7:26 
AnswerRe: MSXML load - not able to read chinese characters in path Pin
Victor Nijegorodov1-Mar-18 10:24
Victor Nijegorodov1-Mar-18 10:24 
QuestionRe: MSXML load - not able to read chinese characters in path Pin
Randor 1-Mar-18 14:46
professional Randor 1-Mar-18 14:46 
AnswerRe: MSXML load - not able to read chinese characters in path Pin
Gopi Nath19-Mar-18 23:18
Gopi Nath19-Mar-18 23:18 
QuestionGiven two numbers say a and b. Print their XOR after making the lengths of their binary representation equal by adding trailing zeros to the binary representation of smaller one. Pin
Tarun Jha25-Feb-18 10:14
Tarun Jha25-Feb-18 10:14 
Input:
The first line of the input contains integer T denoting the number of test cases. For each test case, there are two integer inputs a & b.

Output:
For each test case, the output is the integer displaying the XOR of a & b after making them of equal lengths.

Constraints:
1<=T<=100
1<=a,b<=107

Example:
Input:
4
2 6
3 10
5 24
1 20
Output:
2
6
12
4

Explanation:
1. The binary representation of 2 is 10 and of 6 is 110. As the length of "10" is smaller, so add a '0' to it making it "100', to make the length of binary representations equal. XOR of 100 and 110 gives 010 which is 2.

Below is my code
#include <iostream>
#include <cmath>
#include <sstream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
	int cases, binary[100];
	cin>>cases;

	int *result = new int[cases];
	int j;
	for(j=0; j<cases; j++){
		
        stringstream ss[3];
		for(int k=0; k<2; k++)
		{
			int n;
			cin>>n;
			int temp=n, i=0, len;
			while(temp > 0){
				binary[i] = temp%2;
				temp /= 2;
				i++;
			}
			len = i;

			string str ;
			for(int i=0; i<len; ++i){
				stringstream ss;
				ss << binary[(len-1)-i];
				str += ss.str() ;
			}
			ss[k] << str;
		}

    	string str1 = ss[0].str(), str2 = ss[1].str();
	    int len = (str1.length() > str2.length()) ? str1.length() : str2.length() ;

    	if(str1.length() < (unsigned)len){
       	 int diff = len - str1.length();
       	 for(int i=0; i<diff; ++i){
        	    str1 += '0';
    	    }
   	 	}
    	else if(str2.length() < (unsigned)len){
      	  int diff = len - str2.length();
       	 for(int i=0; i<diff; ++i){
        	    str2 += '0';
    	    }
   	 	}

   	 	string str3 = str1;
  	  	for(int i=0; i<len; ++i){
   	    	 if(str1[i]==str2[i]){
    	        str3[i]='0';
    	    }else   str3[i]='1';
    	}
		int length = str3.length(), val=0;
 	   	for(int i=0, m=length-1; i<length, m>=0; ++i,--m){
       		if(str3[i] == '1'){
	        	    val += pow(2, m);
    	   	 }
   	 	}
   	 	result[j] = val;
	}

	for(int i=0; i<cases; i++){
		cout<<result[i]<<endl;
	}
	return 0;
}


how to make it more efficient & short(i haven't studied oops yet)
AnswerRe: Given two numbers say a and b. Print their XOR after making the lengths of their binary representation equal by adding trailing zeros to the binary representation of smaller one. Pin
Richard MacCutchan25-Feb-18 21:54
mveRichard MacCutchan25-Feb-18 21:54 
AnswerRe: Given two numbers say a and b. Print their XOR after making the lengths of their binary representation equal by adding trailing zeros to the binary representation of smaller one. Pin
CPallini25-Feb-18 23:17
mveCPallini25-Feb-18 23:17 
GeneralRe: Given two numbers say a and b. Print their XOR after making the lengths of their binary representation equal by adding trailing zeros to the binary representation of smaller one. Pin
Richard MacCutchan25-Feb-18 23:32
mveRichard MacCutchan25-Feb-18 23:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.