倒数第一
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 1e6 + 10;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long int ll;
#define f(i,a,n) for(int i=a;i<n;++i)
#define ff(i,a,n) for(int i=a;i<=n;++i)
#define fre freopen("1.txt","r",stdin)
int main(){
multiset<char>q;
string s;
cin>>s;
for(int i=0;i<s.size();i++ ){
q.insert(s[i]);
}
for(auto z:q){
cout<<z<<" ";
}
return 0;
}
倒数第二
//class String {
//public:
// String( const char *str = NULL ); /// 构造函数
// String( const String &other ); /// 拷贝构造函数
// String& operator = ( const String &other ); /// 赋值函数
// void output( void ); /// 输出字符串
// ~String( void ); /// 析构函数
//private:
// int length; /// 用于保存字符串长度
// char *m_data; ///用于保存字符。注意:无需以'\0'作为字符串结束标志
//};
/*
请在此处编写类代码
*/#include<iostream>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 1e6 + 10;
typedef long long int ll;
#define f(i,a,n) for(int i=a;i<n;++i)
#define ff(i,a,n) for(int i=a;i<=n;++i)
#define fre freopen("1.txt","r",stdin)
class String{
char *data;int length;
public:
String(){
data = NULL;
length = 0;
}
String(char a[]){/// 构造函数
length = strlen(a);
data=new char[length];
for(int i=0; i<length;i++){
if(a[i]=='\0'||a[i]=='\t'||a[i]=='\r')break;
else data [i]=a[i];
}
}
~String(){
if(data != NULL)delete []data;
data =NULL;
}
int size(){
int siz=0;
f(i,0,length)siz++;
return siz;
}
void output(){/// 输出字符串
for(int i=0; i<length;i++)cout<<data[i];
}
String( String & r){ // 拷贝构造函数
length=r.length;
if(data)delete[]data,data=NULL;
data = new char [r.length];
for(int i=0;i<length;i++)data[i]=r.data[i];
}
String &operator= ( const String &b ) {/// 赋值函数
if ( this != &b ) { // 如果不是自己赋值给自己,如 a = a;
if ( length > 0 ) {
delete []data;
data = NULL;
length = 0;
}
length = b.length;
if ( length > 0 ) { // b不空
data = new char[length];
for ( int i = 0; i < length; i++ )
data[i] = b.data[i];
}
}
return *this;
}
String& operator + ( String& str ){
char* s=new char[length + str.length-1] ;
length=length + str.length;
strcpy(s,data);
strcat(s,str.data);
delete[] data;
data=s;
return *this;
}
};
int main(){
String s1( "apple" ); /// 创建一个字符串对象s1
s1.output();
printf( "\n" );
String s2; /// 创建一个字符串对象s2
s2.output(); /// 输出s2。 由于s2是空的,所以没有输出任何内容
printf( "\n" ); /// 只输出了一个空行
s2 = s1; /// 对象赋值
s2.output();
printf( "\n" );
String s3( s1 ); /// 创建一个字符串对象s3,测试拷贝构造函数
s3.output();
printf( "\n" );
String s4( "pear" ); /// 创建一个字符串对象s1
s2 = s4; /// 对象赋值
s2.output();
printf( "\n" );
return 0;
}
倒数第三,第一题
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
class CWin // 定义类 CWin
{
private:
char id, *title;
public:
CWin( char i = 'D', char *text = "Default window" ) : id( i )
{
title = new char[50];
strcpy( title, text );
}
void set_data( char i, char *text )
{
id = i;
strcpy( title, text );
}
CWin &operator =(CWin &win) // 定义重载运算符「=」
{
id = win.id;
strcpy ( this->title, win.title );
return *this;
}
void show( void )
{
cout << "Window " << id << ": " << title << endl;
}
~CWin()
{
delete [] title;
}
CWin (CWin &win) // 拷贝构造函数
{
id = win.id;
strcpy( title, win.title );
}
};
int main( )
{
CWin win1( 'A', "Main window" );
CWin win2( 'B', "Big window" );
CWin win3;
win1.show();
win2.show();
win3.show();
win1 = win2 = win3; // 设定 win1 = win2 = win3
win1.set_data( 'A', "Hello window" ); // 修改win1的内容
cout << "设定 win1=win2=win3, 并更改win1的成员之后 ..." << endl;
win1.show();
win2.show();
win3.show();
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)