how to find the number of the changes happened between 2 string?!!

Young Froid was playing with a string. After lots of operations he wants to know how many characters have been changed in this string.

Input
You are given two strings S and T, both of the same length. Their lengths don't exceed 1000.

Output
Print the number of different characters.

http://postimg.org/image/x4jom6xpz/ :/
if(str1[i] != str2[i]) count++;
Use the ASCII table to compare the values of each char individually. Add one to a counter for every time the chars are not the same value. Here is a very quick idea of what I'm talking about to get your mind thinking. In your program, you are going to have to use a file stream to compare the chars of each string individually, and a for loop. anup30 summarized it well above.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

int main()
{
	int counter = 0, x = 'A', y = 'B';

	if (x != y)
		counter += 1;
	else;

	cout << "there are " << counter << " diferences." << endl;

	counter = 0;

	x = 'B';

	if (x != y)
		counter += 1;
	else;

	cout << "there are " << counter << " diferences." << endl;

	cin.get();
	return(0);
}
Last edited on
Topic archived. No new replies allowed.