📄 main.cpp
字号:
/*
#include<iostream.h>
#include<string.h>
#include<stdio.h>
void main()
{
const int m=5;
char string[m][20];
int i, j;
for(int temp=0; ;temp++)
{
bool flag=true;
for(i=0; i<m; i++)
gets(string[i]);
for(i=0; i<m; i++)
for(j=0; j<20; j++)
if(string[i][j]==' ')
{
flag=false;
cout << "输入不合法,请用Enter键结束一个字符串的输入!" << endl;
cout << "请重新输入:" << endl;
}
if(flag)
break;
}
for(i=0; i<m; i++)
{
int small=0;
for(j=0; j<20; j++)
{
for(int temp1=j+1; j<20; j++)
{
if(string[i][temp1]<string[i][small])
small=temp1;
}
char n;
n=string[i][small];
string[i][small]=string[i][j];
string[i][j]=n;
}
}
cout << "--------------"<< endl;
for(i=0; i<m; i++)
cout << string[i] << endl;
}
*/
/*
#include <iostream>
#include <string>
using namespace std;
int main()
{
void sort(char **p); //这个函数主要处理的是使用指向指针的指针
const int m=20; //多用于处理指针数组的问题
int i;
char **p,*pstr[5],str[5][m];
for(i=0;i<5;i++)
{
pstr[i]=str[i];
}
cout<<"请输入5个字符串:"<<endl;
for(i=0;i<5;i++)
{
cin>>pstr[i];
}
p=pstr;
sort(p);
cout<<"排序后为:"<<endl;
for(i=0;i<5;i++)
{
cout<<pstr[i]<<endl;
}
return 0;
}
void sort(char **p)
{
int i,j;
char *temp;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(*(p+i),*(p+j))>0) //比较交换
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
} //实现!!!
*/
/*
#include <iostream>
using namespace std;
void rst(char *p) //这个函数是把一个字符串由小到大排列
{
int i,j;
char x;
for(i=0;*(p+i)!='\0';i++)
{
for(j=i;*(p+j)!='\0';j++)
{
if(*(p+i)>*(p+j))
{
x=*(p+i);
*(p+i)=*(p+j);
*(p+j)=x;
}
}
}
}
void sort(char **p)//这个函数是把五个字符串进行排列
{
int i,j;
char *temp;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(strcmp(*(p+i),*(p+j))>0) //比较交换
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
}
int main()
{
const int m=20;
char s[5][m];
char **p,*ps[5];
int i,j;
for(i=0;i<5;i++)
{
ps[i]=s[i];
}
cout<<"请输入5个字符串"<<endl;
for(i=0;i<5;i++)
{
cin>>s[i];
}
for(i=0;i<5;i++)
{
rst(ps[i]);
}
cout<<"字符串排列后为:"<<endl;
for(i=0;i<5;i++)
{
cout<<ps[i]<<endl;
}
p=ps;
sort(p);
cout<<"排序后为:"<<endl;
for(i=0;i<5;i++)
{
cout<<ps[i]<<endl;
}
}
*/
/*
#include<iostream.h>
#include<string.h>
void main()
{
char s[5][20]={"Data", "Wang", "li", "truth", "tell"};
char (*p)[20];
char t1;
char ts[20];
for(int tp=0; tp<5; tp++)
for(int i=0; i<20; i++)
for(int j=i; j<20; j++)
{
if(*(*(p+tp)+i)>*(*(p+tp)+j))
{
t1=*(*(p+tp)+i);
*(*(p+tp)+i)=*(*(p+tp)+j);
*(*(p+tp)+j)=t1;
}
}
cout <<*p;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -