Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import 'dart:convert';
  2. import 'dart:io';
  3.  
  4. main() {
  5. /// No. of Different Characters in the two Strings;
  6. int diff = 0;
  7.  
  8. /// No. of Identical Characters in the two Strings;
  9. int correct = 0;
  10.  
  11. /// Print Msg for User;
  12. print("hi enter string 1");
  13.  
  14. /// Input Code
  15. var line = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
  16.  
  17. /// Print Msg for User;
  18. print("hi enter string 2");
  19.  
  20. /// Input Code
  21. var line2 = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
  22.  
  23. /// Calculating the largest Length of the two strings to be Loop Length;
  24. int loopLength = line.length > line2.length ? line.length : line2.length;
  25.  
  26. /// Looping on -
  27. for (int i = 0; i < loopLength; i++) {
  28. /// If string length <= i, then there is no string to check so counting++
  29. if (line.length <= i || line2.length <= i) {
  30. print("length <= $i");
  31. diff++;
  32.  
  33. /// Stop executing the checks, we already know what we want;
  34. continue;
  35. }
  36.  
  37. /// Normal equal between characters if not equal counting++
  38. if (line[i] != line2[i]) {
  39. print("diff at $i [${line[i]},${line2[i]}]");
  40. diff++;
  41.  
  42. /// Stop executing the checks, we already know what we want;
  43. continue;
  44. }
  45.  
  46. /// If all the checks are invalid then it's Identical Characters;
  47. print("correct ${line[i]}");
  48. correct++;
  49. }
  50.  
  51. /// Printing Result;
  52. print("diff $diff , correct $correct");
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement