Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include<iostream>
- #include<string.h>
- int main(void)
- {
- char string1[100], string2[100], string3[100], temp, wat;
- int n, i, j, m, k, h, p, q;
- printf("Please enter your first string: ");
- gets_s(string1);
- printf("Please enter your second string: ");
- gets_s(string2);
- strcat_s(string1, string2);
- n = strlen(string1);
- for (i = 0; i<n - 1; i++)
- {
- for (j = i + 1; j<n; j++)
- {
- int s = tolower(string1[i]) - tolower(string1[j]);
- if (s == 0)
- { // letters are the same... now watch out for case
- s = string1[i] - string1[j];
- }
- if (s > 0)
- {
- temp = string1[i];
- string1[i] = string1[j];
- string1[j] = temp;
- }
- }
- }
- printf("%s", string1);
- m = strlen(string2);
- for (k = 0; k<m - 1; k++)
- {
- for (h = k + 1; h < m; h++)
- {
- int g = tolower(string2[k]) - tolower(string2[h]);
- if (g == 0)
- { // letters are the same... now watch out for case
- g = string2[k] - string2[h];
- }
- if (g > 0)
- {
- wat = string2[k];
- string2[k] = string2[h];
- string2[h] = wat;
- }
- }
- }
- // printf("\n%s", string2); string2는 입력받은 단어만 알파벳순서로 정렬되어서 나오고 string1는 입력받은 두개의 문자열의 연결된 형태로 나옴
- for (q = 0; q <n + 1; q++)
- {
- // for (p = q; p <n + 1; p++)
- // {
- if (string1[q] == string1[q+1])
- {
- printf("\n[x] : %c\n", string1[q]);
- }
- if (string1[q] != string1[q + 1])
- {
- q++;
- }
- // }
- }
- /*for (q = 0; q <n + 1; q++)
- {
- for (p = q; p <n + 1; p++)
- {
- if (string1[q] == string1[p + 1])
- {
- string1[q] = NULL;
- printf("\n[x] : %c", string1[p + 1]);
- }
- else break;
- }
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment