69,369
社区成员
发帖
与我相关
我的任务
分享
please input the string:
1qaz2!wsx$#&*
12 aqswxz !#$&*
Press any key to continue
#include <stdio.h>
#include <string.h>
#define MAXLENGTH 255
#define NUMBER 0
#define LETTER 1
#define SPECIAL 2
char string [3][MAXLENGTH] ;
void order (char *) ;
void judge (int, char *) ;
void main ()
{
char str[MAXLENGTH] ;
printf ("please input the string:\n") ;
scanf ("%s", str) ;
if (str[0] >= '0' && str[0] <= '9')
judge (NUMBER, str) ;
else if (str[0] >= 'a' && str[0] <= 'z'
|| str[0] >= 'A' && str[0] <= 'Z')
judge (LETTER, str) ;
else judge (SPECIAL, str) ;
printf ("%s %s %s\n", string[0], string[1], string[2]) ;
}
void judge (int sort, char *str)
{
static int num = 0 ;
static int lett = 0 ;
static int spec = 0 ;
static int location = 0 ;
if (NUMBER == sort)
string [sort][num ++] = str[location++] ;
else if (LETTER == sort)
string [sort][lett++] = str[location++] ;
else
string [sort][spec++] = str[location++] ;
order (string [sort]) ;
if (!str[location]) return ;
else if (str[location] >= '0' && str[location] <= '9')
judge (NUMBER, str) ;
else if (str[location] >= 'a' && str[location] <= 'z'
|| str[location] >= 'A' && str[location] <= 'Z')
judge (LETTER, str) ;
else judge (SPECIAL, str) ;
}
void order (char *string)
{
int len = strlen (string) ;
for (int i = 0; i < len - 1; i++)
if (string[len - 1] < string[i])
{
char temp = string[len - 1] ;
for (int j = len - 1; j > i; j--)
string[j] = string[j-1] ;
string[i] = temp ;
}
}
1qaz2!wsx$#&* ==> 12 qazwsx !$#&*
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
char estr[3][256];
int inds[3];
int main()
{
char *str="1qaz2!wsx$#&*";
char *src = str;
int ind;
loop:
if(isdigit(*src)) ind=0;
else if(isalpha(*src)) ind=1;
else ind=2;
estr[ind][inds[ind]++] = *src++;
if(*src != '\0') goto loop;
printf("%s ==> %s %s %s",str,estr[0],estr[1],estr[2]);
return 0;
};
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
char num[256];
char alp[256];
char otr[256];
void extract(const char* str,int np, int ap, int op)
{
if (*str=='\0') return;
if (isdigit(*str))
*(num+np++) = *str++;
else if(isalpha(*str))
*(alp+ap++) = *str++;
else
*(otr+op++) = *str++;
return extract(str,np,ap,op);
}
int main()
{
char *str="1qaz2!wsx$#&*";
extract(str,0,0,0);
puts(num);
puts(alp);
puts(otr);
return 0;
};
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
char *num;
char *alp;
char *otr;
void init();
void finish();
void shows();
void extract(const char* str,int np, int ap, int op)
{
if (*str=='\0') return;
if (isdigit(*str))
*(num+np++) = *str++;
else if(isalpha(*str))
*(alp+ap++) = *str++;
else
*(otr+op++) = *str++;
return extract(str,np,ap,op);
}
int main()
{
char *str="1qaz2!wsx$#&*";
init();
extract(str,0,0,0);
shows();
finish();
return 0;
}
void init()
{
num = calloc(256,sizeof(char));
alp = calloc(256,sizeof(char));
otr = calloc(256,sizeof(char));
};
void finish()
{
free(num);
free(alp);
free(otr);
};
void shows()
{
puts(num);
puts(alp);
puts(otr);
};
#include <stdio.h>
#include <string.h>
#define MAXLENGTH 255
#define NUMBER 0
#define LETTER 1
#define SPECIAL 2
char string [3][MAXLENGTH] ;
void judge (int, char *) ;
void main ()
{
char str[MAXLENGTH] ;
printf ("please input the string:\n") ;
scanf ("%s", str) ;
if (str[0] >= '0' && str[0] <= '9')
judge (NUMBER, str) ;
else if (str[0] >= 'a' && str[0] <= 'z'
|| str[0] >= 'A' && str[0] <= 'Z')
judge (LETTER, str) ;
else judge (SPECIAL, str) ;
printf ("%s %s %s\n", string[0], string[1], string[2]) ;
}
void judge (int sort, char *str)
{
static int num = 0 ;
static int lett = 0 ;
static int spec = 0 ;
static int location = 0 ;
if (NUMBER == sort)
string [sort][num ++] = str[location++] ;
else if (LETTER == sort)
string [sort][lett++] = str[location++] ;
else
string [sort][spec++] = str[location++] ;
if (!str[location]) return ;
else if (str[location] >= '0' && str[location] <= '9')
judge (NUMBER, str) ;
else if (str[location] >= 'a' && str[location] <= 'z'
|| str[location] >= 'A' && str[location] <= 'Z')
judge (LETTER, str) ;
else judge (SPECIAL, str) ;
}
please input the string:
1qaz2!wsx$#&*
12 qazwsx !$#&*
Press any key to continue
#include <stdio.h>
#include <string.h>
#define MAXLENGTH 255
char numberstr [MAXLENGTH] ;
char letterstr [MAXLENGTH] ;
char specialstr[MAXLENGTH] ;
void number (char *, int) ;
void letter (char *, int) ;
void special (char *, int) ;
void main ()
{
char str[MAXLENGTH] ;
printf ("please input the string:\n") ;
scanf ("%s", str) ;
if (str[0] >= '0' && str[0] <= '9')
number (str, 0) ;
else if (str[0] >= 'a' && str[0] <= 'z'
|| str[0] >= 'A' && str[0] <= 'Z')
letter (str, 0) ;
else special (str, 0) ;
printf ("%s %s %s\n", numberstr, letterstr, specialstr) ;
}
void number (char *str, int location)
{
static int i = 0 ;
numberstr[i++] = str[location++] ;
if (!str[location]) return ;
else if (str[location] >= '0' && str[location] <= '9')
number (str, location) ;
else if (str[location] >= 'a' && str[location] <= 'z'
|| str[location] >= 'A' && str[location] <= 'Z')
letter (str, location) ;
else special (str, location) ;
}
void letter (char *str, int location)
{
static int i = 0 ;
letterstr[i++] = str[location++] ;
if (!str[location]) return ;
else if (str[location] >= '0' && str[location] <= '9')
number (str, location) ;
else if (str[location] >= 'a' && str[location] <= 'z'
|| str[location] >= 'A' && str[location] <= 'Z')
letter (str, location) ;
else special (str, location) ;
}
void special (char *str, int location)
{
static int i = 0 ;
specialstr[i++] = str[location++] ;
if (!str[location]) return ;
else if (str[location] >= '0' && str[location] <= '9')
number (str, location) ;
else if (str[location] >= 'a' && str[location] <= 'z'
|| str[location] >= 'A' && str[location] <= 'Z')
letter (str, location) ;
else special (str, location) ;
}