Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include<iostream>
  3. #include<string.h>
  4. int main(void)
  5. {
  6. char string1[100], string2[100], string3[100], temp, wat;
  7. int n, i, j, m, k, h, p, q;
  8.  
  9. printf("Please enter your first string: ");
  10. gets_s(string1);
  11. printf("Please enter your second string: ");
  12. gets_s(string2);
  13.  
  14. strcat_s(string1, string2);
  15.  
  16. n = strlen(string1);
  17.  
  18. for (i = 0; i<n - 1; i++)
  19. {
  20. for (j = i + 1; j<n; j++)
  21. {
  22. int s = tolower(string1[i]) - tolower(string1[j]);
  23. if (s == 0)
  24. { // letters are the same... now watch out for case
  25. s = string1[i] - string1[j];
  26. }
  27.  
  28. if (s > 0)
  29. {
  30. temp = string1[i];
  31. string1[i] = string1[j];
  32. string1[j] = temp;
  33. }
  34. }
  35. }
  36. printf("%s", string1);
  37.  
  38. m = strlen(string2);
  39. for (k = 0; k<m - 1; k++)
  40. {
  41. for (h = k + 1; h < m; h++)
  42. {
  43. int g = tolower(string2[k]) - tolower(string2[h]);
  44. if (g == 0)
  45. { // letters are the same... now watch out for case
  46. g = string2[k] - string2[h];
  47. }
  48.  
  49. if (g > 0)
  50. {
  51. wat = string2[k];
  52. string2[k] = string2[h];
  53. string2[h] = wat;
  54. }
  55. }
  56. }
  57. // printf("\n%s", string2); string2는 입력받은 단어만 알파벳순서로 정렬되어서 나오고 string1는 입력받은 두개의 문자열의 연결된 형태로 나옴
  58.  
  59. for (q = 0; q <n + 1; q++)
  60. {
  61. // for (p = q; p <n + 1; p++)
  62. // {
  63. if (string1[q] == string1[q+1])
  64. {
  65. printf("\n[x] : %c\n", string1[q]);
  66. }
  67. if (string1[q] != string1[q + 1])
  68. {
  69. q++;
  70. }
  71. // }
  72. }
  73.  
  74.  
  75.  
  76. /*for (q = 0; q <n + 1; q++)
  77. {
  78. for (p = q; p <n + 1; p++)
  79. {
  80. if (string1[q] == string1[p + 1])
  81. {
  82. string1[q] = NULL;
  83. printf("\n[x] : %c", string1[p + 1]);
  84. }
  85.  
  86. else break;
  87. }
  88. }*/
  89.  
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement