C语言题目6

IT小小龙 posted @ 2014年4月04日 22:29 in C with tags 字符串 , 593 阅读
//用C编写程序:输入一个字符串,将其中的数字字符移动到非数字字符之后,
//并保持数字字符和非数字字符输入时的顺序。
#include"stdio.h"
#include"stdlib.h"

typedef struct node{
  char x;
  struct node *next;
}llnode;

int main()
{
  char c;
  llnode *head = (llnode *)malloc(sizeof(llnode));
  llnode *p;
  llnode *n;
  head->next = NULL;
  //由于不知道用户会输入多少字符,所以要用链表
  printf("请输入一个字符串,输入完成后敲击回车:");
  while(1)
    {
      c = getchar();
      if(c == '\n')
	{
	  break;
	}
      n = (llnode *)malloc(sizeof(llnode));
      n->x = c;
      n->next = NULL;
      if(head->next == NULL)
	{
	  head->next = n;
	}
      else
	{
	  p = head->next;
	  if((n->x)>='0' && (n->x)<='9')
	    {
	      while(p->next != NULL)
		{
		  p = p->next;
		}
	      p->next = n;
	    }
	  else
	    {
	      while(p->next != NULL)
		{
		  if((p->next->x)>='0' && (p->next->x)<='9')
		    {
		      n->next = p->next;
		      p->next = n;
		      break;
		    }
		  else
		    {
		      p = p->next;
		    }
		}
	      p->next = n;
	    }
	}
    }
  //调整完毕,下面输出
  p = head->next;
  while(p)
    {
      printf("%c", p->x);
      p = p->next;
    }
  printf("\n");
  return 1;
}
Avatar_small
Raj SSP 说:
2022年8月10日 16:00

Rajasthan Social Security Pension program is a scheme launched by State Government of Rajasthan. It is for the purpose of the Welfare of their Residents. Under this scheme, the needy people are going to benefit and provide them financial support for their survival. Raj SSP In this scheme, the destitute widows, senior citizens, disabled people are going to be provided benefits in terms of money. There is a pop registration process and a flow of processes, need to avail benefits under RAJSSP scheme.

Avatar_small
GSEB STD-4 Model Pap 说:
2022年9月12日 18:05

GSEB STD-4 Model Paper 2023 Pdf Download for Gujarat State Elementary Level Primary School 4th Class Question Paper Pdf with Answers for Gujarati Medium, Hindi Medium, English Medium & Urdu Medium Students of Gandhinagar Board at GSEB STD-4 Model Paper. Subject experts of the state and teaching staff of private schools have prepared and suggested the GSEB STD-4 Model Paper 2023 Pdf for Part-A, Part-B, Part-C and Part-D exams. Set wide solved question paper suggested as Gujarat Board 4th Class Model Paper 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter