/*
(1) , ;
(2) , ;
(3) ;
(4) , ;
(5) , ;
(6) , , , ;
(7) , 。
(8) main , 。
*/
#include
#include
using namespace std;
class m_string
{
public:
m_string();
m_string(string s[10]);
m_string(const m_string &s);
void print();
void setdata();
~m_string();
char* mindata(int num[]);
void InsertSort();
private:
string data[10];
};
char ch[10];
m_string::m_string()
{
for(int i = 0; i < 10; i++)
{
data[i] = "";
}
}
m_string::m_string(const m_string &s)
{
for(int i = 0; i < 10; i++)
{
data[i] = s.data[i];
}
}
m_string::m_string(string s[10])
{
for(int i = 0; i < 10; i++)
{
data[i] = s[i];
}
}
void m_string::print()
{
cout << " :" << endl;
for(int i = 0; i < 10; i++)
{
cout << data[i] << endl;
}
cout << endl;
}
void m_string::setdata()
{
cout << " :" << endl;
for(int i = 0; i < 10; i++)
{
cin >> data[i];
}
}
char* m_string::mindata(int num[])
{
for(int i = 0; i < 10; i++)
{
ch[i] = data[i][0];
num[i] = 0;
for(int j = 0; data[i][j] != '\0'; j++)
{
if(data[i][j] < ch[i])
{
ch[i] = data[i][j];
num[i] = 0;
}
if(data[i][j] == ch[i])
num[i]++;
}
}
return ch;
}
void m_string::InsertSort()
{
int i = 9; // ,
while(i> 0)
{
int pos = 0; // ,
for(int j = 0; j< i; j++)
if(data[j]>data[j + 1])
{
pos = j; //
string tmp = data[j]; data[j] = data[j + 1]; data[j + 1] = tmp;
}
i = pos; //
}
}
m_string::~m_string()
{
}
int main()
{
string a[10] = { "a12","b22","c23","d33","a35","c55","e66","t45","f75","g88" };
int count[10];
m_string s1;
cout << "s1";
s1.print();
m_string s3(a);
cout << "s3";
s3.print();
m_string s2(s3);
cout << "s2";
s2.print();
s1.setdata();
char *ch = s1.mindata(count);
cout << " :" << ch << endl;
cout << " : ";
for(int i = 0;i < 10;i++)
cout << count[i];
cout << endl;
s2.InsertSort();
s2.print();
return 0;
}
/*
1232
15496
5462545
552468852
55879545
3325482
215526875
5884569846
86598898986
878987879
*/