Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int length, i = 0, j = 0, same=0, different=0;
  6. char string1[101];
  7. char string2[101];
  8. printf("Please enter the length of the two stringsn");
  9. scanf("%d", &length);
  10. getchar();
  11.  
  12. printf("nPlease enter the first stringn");
  13. while((string1[i] = getchar())!='n')
  14. i++ ;
  15. string1[i] = '';
  16.  
  17. printf("nPlease enter the second stringn");
  18. while((string2[j] = getchar())!='n')
  19. j++ ;
  20. string2[j] = '';
  21.  
  22. for(i=0; i<=(length-1); i++){
  23. for(j=0; j<=(length-1); j++){
  24. if(string1[i]==string2[j] || string1[i]==string2[j] + 32 || string1[i]==string2[j] - 32){
  25. same++;
  26. }
  27. if(string1[i]!=string2[j] || string1[i]!=string2[j] + 32 || string1[i]!=string2[j] - 32){
  28. different++;
  29. }
  30. }
  31.  
  32. }
  33.  
  34. if(same>=length && different<=length*length){
  35. printf("nThe two strings are the same!");
  36. }
  37. else{
  38. printf("nThe two strings are not the same!");
  39. }
  40.  
  41. return 0;
  42. }
  43.  
  44. char *str1; //all ready to go
  45. char *str2; //also ready to go
  46. int countOne[128] = {0}, countTwo[128] = {0}, ndx, equal = 1;
  47. while (*str1) {
  48. if (*str1 >= 'A' && *str1 <= 'Z')
  49. countOne[*str1++ + 'a' - 'A']++;
  50. else
  51. countOne[*str1++]++;
  52. }
  53. while (*str2) {
  54. if (*str2 >= 'A' && *str2 <= 'Z')
  55. countOne[*str2++ + 'a' - 'A']++;
  56. else
  57. countOne[*str2++]++;
  58. }
  59. for (ndx = 0; ndx < 128 && equal; ndx++)
  60. equal = countOne[ndx] == countTwo[ndx];
  61.  
  62. //equal now has whether they are equal.
  63.  
  64. main()
  65. {
  66. char s[120],t[120];
  67. int i,j,extra;
  68. printf("enter first string:");
  69. gets(s);
  70. flushall();
  71. printf("enter second string:");
  72. gets(t);
  73. for(i=0;s[i];i++)
  74. {
  75. if(s[i]>=65&&s[i]<=90)
  76. s[i]+=32;
  77. for(j=0;t[j];j++)
  78. {
  79. if(t[j]>=65&&t[j]<=90)
  80. t[j]+=32;
  81. if(s[i]==t[j])
  82. {
  83. t[j]=1;
  84. break;
  85. }
  86. }
  87. if(!t[j])
  88. break;
  89. }
  90. for(i=extra=0;t[i];i++)
  91. if(t[i]!=1)
  92. extra++;
  93. if(!s[i] && extra==0)
  94. printf("matched");
  95. else
  96. printf("not matched");
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement