字符串按大小写排序,大写在前,小写在后,比如AaBCcD

字符串带小写排序,大写在前,小写在后

#include <stdio.h>
#include<string.h>
#define MAX 256
using namespace std;

MyClass::MyClass(QWidget *parent)
QMainWindow(parent)
{
ui.setupUi(this);
test();
}

void MyClass::test()
{
printf(“Please enter a string:\n”);
char s[MAX];
char tmp[MAX];

char* p = s;
char temp, ch;
int n = 0;
gets(s);

/*判断字符串长度*/
while (*p != '\0')
{
	tmp[n] = *p;
	n++;
	p++;

}

TurnChar(s);

/*冒泡排序*/
for (int i = 0; i<n; i++)
	for (int j = i; j<n; j++)
	{
		if (s[j]<s[i])
		{
			temp = s[j];
			s[j] = s[i];
			s[i] = temp;
		}
	}

char *q;
q = tmp;
while (*q != '\0')
{
	if ((*q >= 'a') && (*q <= 'z'))
	{
		*q = *q - 32;
		for (int i = 0; i<n; i++)
		{
			if (i<n-1)
			{
				if (s[i] == *q && s[i]<s[i + 1])
				{
					printf("***\n");
					s[i] = *q + 32;
				}
			}
			else
			{
				if (s[n-1] == *q)
				{
					printf("***123***\n");
					s[n-1] = *q + 32;
				}
			}
		}
	}
	q++;
}
printf("%s\n", s);
return;

}

//转换字符串中大字字母为小写
void MyClass::TurnChar(char a[])
{
char *p;
p = a;
while (*p != ‘\0’)
{
if ((*p >= ‘a’) && (*p <= ‘z’))
*p = *p - 32;
p++;
}
}

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值