中大-复试-2012(2011)-编程题一

来源:互联网 发布:古法酱油知乎 编辑:程序博客网 时间:2024/05/08 22:29

题目:把一个字符串分类,左边是数字,右边是字母。

输入:3j35j3de

输出:3353jjde

#include <stdio.h>#include <string.h>int main(){    char str[100], temp;    int i, j, len;    while (scanf("%s", str) != EOF) {        i = 0; len = (int)strlen(str); j = len-1;        while (i < j) {            while (i < j && (str[i] >= '0' && str[i] <= '9')) {                i++;            }            while (i < j && ((str[j] <= 'z' && str[j] >= 'a') || (str[j] >= 'A' && str[j] <= 'Z'))) {                j--;            }            if (i <= len && j>= 0) {                temp = str[i];                str[i] = str[j];                str[j] = temp;            }        }        printf("%s\n", str);    }    return 0;}


0 0
原创粉丝点击