zoukankan      html  css  js  c++  java
  • 字符串移动,字符串为*号和26个字母的任意组合,把*都移动到最左侧,字母移动到右侧,顺序不变

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    #define   MAX     256
    
    void  move_stars(char* str) {
        int len = strlen(str) - 1;
        char* p = str + len;
        char* q = p;
        for (;len >= 0; --len, --q) {
            if (isalpha(*q)) {
                *p-- = *q;
            }
        }
        ++p;
        while (str != p) {
            *str++ = '*';
        }
    }
    
    int  main(void) {
        char  str[MAX];
        fgets(str, MAX, stdin);
        str[strlen(str)-1] = '';
        move_stars(str);
        fprintf(stderr, "%s
    ", str);
        system("pause");
        return  0;
    }
  • 相关阅读:
    Web基础 网页的血肉CSS
    18
    19
    20
    17
    16
    15
    13
    14
    12
  • 原文地址:https://www.cnblogs.com/coder-zhang/p/3844732.html
Copyright © 2011-2022 走看看