?? 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 + -