Advertisement
MeShootIn

8

May 17th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. /*
  2. ËÀÁÎÐÀÒÎÐÍÀß ÐÀÁÎÒÀ ¹ 9.1
  3. ÂÀÐÈÀÍÒ 20
  4. ÂÛÏÎËÍÈË: ÄÌÈÒÐÈÉ ÌÈØÓÒÈÍ ÊÝ - 101
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10.  
  11. using namespace std;
  12.  
  13. void my_swap(char &a, char &b){
  14.     char tmp = a;
  15.     a = b;
  16.     b = tmp;
  17. }
  18.  
  19. void sort_str(char * str){
  20.     int n = strlen(str);
  21.     for(int i = 0; i < n; i++){
  22.         for(int j = 0; j < n - i - 1; j++){
  23.             if(str[j] != ' ' && str[j + 1] != ' ' && str[j] > str[j + 1]){
  24.                 my_swap(str[j], str[j + 1]);
  25.             }
  26.         }
  27.     }
  28. }
  29.  
  30. void scan_str(char * str){
  31.     int i = 0;
  32.     char ch = '\0';
  33.     while(true){
  34.         scanf("%c", &ch);
  35.         if(ch == '\n'){
  36.             break;
  37.         }
  38.         str[i] = ch;
  39.         i++;
  40.     }
  41. }
  42.  
  43. int main(){
  44.     char * str = (char *) malloc(100 * sizeof(char));
  45.    
  46.     scan_str(str);
  47.     sort_str(str);
  48.    
  49.     printf("%s", str);
  50.     free(str);
  51.    
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement