Created
August 7, 2019 16:50
-
-
Save Saifallak/e4b6576ac992dd770bed161fbb200aae to your computer and use it in GitHub Desktop.
just a small code in dart that counting the identical characters and diff characters in two string;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:io'; | |
main() { | |
/// No. of Different Characters in the two Strings; | |
int diff = 0; | |
/// No. of Identical Characters in the two Strings; | |
int correct = 0; | |
/// Print Msg for User; | |
print("hi enter string 1"); | |
/// Input Code | |
var line = stdin.readLineSync(encoding: Encoding.getByName('utf-8')); | |
/// Print Msg for User; | |
print("hi enter string 2"); | |
/// Input Code | |
var line2 = stdin.readLineSync(encoding: Encoding.getByName('utf-8')); | |
/// Calculating the largest Length of the two strings to be Loop Length; | |
int loopLength = line.length > line2.length ? line.length : line2.length; | |
/// Looping on - | |
for (int i = 0; i < loopLength; i++) { | |
/// If string length <= i, then there is no string to check so counting++ | |
if (line.length <= i || line2.length <= i) { | |
print("length <= $i"); | |
diff++; | |
/// Stop executing the checks, we already know what we want; | |
continue; | |
} | |
/// Normal equal between characters if not equal counting++ | |
if (line[i] != line2[i]) { | |
print("diff at $i [${line[i]},${line2[i]}]"); | |
diff++; | |
/// Stop executing the checks, we already know what we want; | |
continue; | |
} | |
/// If all the checks are invalid then it's Identical Characters; | |
print("correct ${line[i]}"); | |
correct++; | |
} | |
/// Printing Result; | |
print("diff $diff , correct $correct"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment