菜鸟求助 各位好 我是一名delphi爱好者但是今天朋友问了我一个c++的问题,我实在是不知道怎么实现了,希望各位帮忙给看看 题目如下:定义 一个二维字符窜数组,输入若干个字符窜,按升序排列后输出。设计一个通用排序函数,输入参数为字符穿数组和要排序的字符穿的个数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写了一个简单的,肯定问题多多,但可以参考一下了。输入字符串时按Ctrl-Z结束。#include <iostream>using namespace std;#include <conio.h>const int MAX_STRING_NUM = 32;const int MAX_STRING_LEN = 128;void sort(char *sarr[32] , int n);int main(){ char **strarray = new char*[MAX_STRING_NUM]; char buf[MAX_STRING_LEN]; cout << "Please input your strings(" << MAX_STRING_NUM << " at most), Ctrl-Z to stop." << endl; int count = 0; for(int i = 0 ; i < MAX_STRING_NUM ; i++) { cout << "String No." << i << ": "; if(cin >> buf) { count++; strarray[i] = new char[strlen(buf) + 1]; strcpy(strarray[i] , buf); } else break; } sort(strarray , count); cout << endl << "Order after sort:" << endl; for(int i = 0 ; i < count ; i++) cout << "No." << i << ": " << strarray[i] << endl; cout << endl << "Press any key to exit..." << endl; getch(); return 0; }//Use bubble sort.void sort(char *sarr[32] , int n){ char buf[MAX_STRING_LEN]; for(int i = 0 ; i < n ; i++) { bool bChanged = false; for(int j = 0 ; j < n - i - 1 ; j++) { if(strcmp(sarr[j] , sarr[j + 1]) > 0) { strcpy(buf , sarr[j]); strcpy(sarr[j] , sarr[j + 1]); strcpy(sarr[j + 1] , buf); bChanged = true; } } if(!bChanged) break; }} "->"这个符号是什么用的? vs2005中visual c++ 如何使用Datagrid(OLEDB)控件呀? (每天一贴) 天下奇谋 第二章 之 暗藏冷箭 关于存放图片的变量类型 有关CFile 整行读取数据的方法。。。。。。(请教) 硬盘数据全丢,散分 如何自动识别并填充一个闭合的区域? 怎样在98系统vc下注册控件ocx控件? 关于PB用OpenFile、ReadFile、llseek DLL的用法 如何得到程序自己所在的完整路徑? 我在对话框种做了一个消息,请问我怎样传递这个消息 100分,急问有关字符串的问题,一定给分。。。。。。。。!!!
输入字符串时按Ctrl-Z结束。#include <iostream>
using namespace std;#include <conio.h>const int MAX_STRING_NUM = 32;
const int MAX_STRING_LEN = 128;void sort(char *sarr[32] , int n);int main()
{
char **strarray = new char*[MAX_STRING_NUM];
char buf[MAX_STRING_LEN];
cout << "Please input your strings(" << MAX_STRING_NUM
<< " at most), Ctrl-Z to stop." << endl;
int count = 0;
for(int i = 0 ; i < MAX_STRING_NUM ; i++)
{
cout << "String No." << i << ": ";
if(cin >> buf)
{
count++;
strarray[i] = new char[strlen(buf) + 1];
strcpy(strarray[i] , buf);
}
else
break;
}
sort(strarray , count);
cout << endl << "Order after sort:" << endl;
for(int i = 0 ; i < count ; i++)
cout << "No." << i << ": " << strarray[i] << endl;
cout << endl << "Press any key to exit..." << endl;
getch();
return 0;
}//Use bubble sort.
void sort(char *sarr[32] , int n)
{
char buf[MAX_STRING_LEN];
for(int i = 0 ; i < n ; i++)
{
bool bChanged = false;
for(int j = 0 ; j < n - i - 1 ; j++)
{
if(strcmp(sarr[j] , sarr[j + 1]) > 0)
{
strcpy(buf , sarr[j]);
strcpy(sarr[j] , sarr[j + 1]);
strcpy(sarr[j + 1] , buf);
bChanged = true;
}
}
if(!bChanged)
break;
}
}