谁帮我编一下这个C++吧!!

来源:百度知道 编辑:UC知道 时间:2024/07/04 05:43:30
从键盘输入任意字符串,以#作为字符串结束标志,如: ak32b2cjfhifj3784mvd# 。
A. 找出字符串中数字的个数和字母的个数,并将这些数字和
字母分别按顺序放入两个一维数组中。
B. 将两个数组的按升序排序。
C. 排序的结果用文件形式存放。

#include <iostream.h>
#include <stdio.h>
#include <fstream.h>
#define path ".\\file.txt"

void BubbleSort(char* p,int length)
{
char temp;
for(int j=0;j<length-1;j++)
{
for(int i=0;i<length-1-j;i++)
{
if(p[i]>p[i+1])
{
temp=p[i];
p[i]=p[i+1];
p[i+1]=temp;
}
}
}
}
void main()
{
char cha[100],num[100],ch[100];
int i=0,len=0,lon=0;
while((cha[i]=getchar())!='#')
{
if(cha[i]>='a'&&cha[i]<='z')
ch[len++]=cha[i];
if(cha[i]>='0'&&cha[i]<='9')
num[lon++]=cha[i];
i++;
}
BubbleSort(ch,len);
BubbleSort(num,lon);
ofstream out(path);
for(int l=0;l<len;l++)
out<<ch[l]<<" ";
out<<endl;
for(l=0;l<lon;l++)
out<<