[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem A: 平面上的点——Point类 (I)
Problem A: 平面上的点——Point类 (I)
Time Limit:1 SecMemory Limit:4 MB
Submit:6011Solved:2151
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和show()方法。
接口描述:
Point::show()方法:按输出格式输出Point对象。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
输出为多行,每行为一个点,X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
1,2 3,3 2,1
Sample Output
Point : (1, 2) Point : (3, 3) Point : (2, 1) Point : (0, 0)
HINT
注意精度控制,C语言的输入输出被禁用。
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream>
#include<iomanip>
using namespace std;
class Point{
private:
double x;
double y;
public:
Point():x(0),y(0){}
Point(double a,double b):x(a),y(b){}
void show()
{
cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")"<<endl;
}
};
int main()
{
char c;
double a, b;
Point q;
while(std::cin>>a>>c>>b)
{
Point p(a, b);
p.show();
}
q.show();
}
[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem B: 平面上的点——Point类 (II)
Problem B: 平面上的点——Point类 (II)
Time Limit:1 SecMemory Limit:4 MB
Submit:5090Solved:2072
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和show()方法,输出各Point对象的构造和析构次序。
接口描述:
Point::show()方法:按输出格式输出Point对象。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
输出每个Point对象的构造和析构行为。对每个Point对象,调用show()方法输出其值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
1,2 3,3 2,1
Sample Output
Point : (0, 0) is created. Point : (1, 2) is created. Point : (1, 2) Point : (1, 2) is erased. Point : (3, 3) is created. Point : (3, 3) Point : (3, 3) is erased. Point : (2, 1) is created. Point : (2, 1) Point : (2, 1) is erased. Point : (0, 0) is copied. Point : (1, 1) is created. Point : (0, 0) Point : (1, 1) Point : (0, 0) Point : (1, 1) is erased. Point : (0, 0) is erased. Point : (0, 0) is erased.
HINT
思考构造函数、拷贝构造函数、析构函数的调用时机。
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream>
#include<iomanip>
using namespace std;
class Point{
private:
double x,y;
public:
Point():x(0),y(0){cout<<setprecision(16)<<"Point : (0, 0) is created."<<endl;}
Point(double a,double b):x(a),y(b){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is created."<<endl;}
Point(double a):x(a),y(1){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is created."<<endl;}
Point(const Point &q){x=q.x;y=q.y;cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is copied."<<endl;}
~Point(){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is erased."<<endl;}
void show(){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")"<<endl;}
};
int main()
{
char c;
double a, b;
Point q;
while(std::cin>>a>>c>>b)
{
Point p(a, b);
p.show();
}
Point q1(q), q2(1);
q1.show();
q2.show();
q.show();
}
[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem C: 平面上的点——Point类 (III)
Problem C: 平面上的点——Point类 (III)
Time Limit:1 SecMemory Limit:4 MB
Submit:3328Solved:1933
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和show()方法,输出各Point对象的构造和析构次序。实现showPoint()函数。
接口描述:
showPoint()函数按输出格式输出Point对象,调用Point::show()方法实现。
Point::show()方法:按输出格式输出Point对象。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
输出每个Point对象的构造和析构行为。showPoint()函数用来输出(通过参数传入的)Point对象的值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
1,2 3,3 2,1
Sample Output
Point : (0, 0) is created. Point : (1, 2) is created. Point : (1, 2) is copied. Point : (1, 2) Point : (1, 2) is erased. Point : (1, 2) is erased. Point : (3, 3) is created. Point : (3, 3) is copied. Point : (3, 3) Point : (3, 3) is erased. Point : (3, 3) is erased. Point : (2, 1) is created. Point : (2, 1) is copied. Point : (2, 1) Point : (2, 1) is erased. Point : (2, 1) is erased. Point : (0, 0) is copied. Point : (1, 1) is created. Point : (0, 0) is copied. Point : (1, 1) is copied. Point : (0, 0) is copied. Point : (0, 0) Point : (1, 1) Point : (0, 0) Point : (0, 0) is erased. Point : (1, 1) is erased. Point : (0, 0) is erased. Point : (1, 1) is erased. Point : (0, 0) is erased. Point : (0, 0) is erased.
HINT
思考构造函数、拷贝构造函数、析构函数的调用时机。
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream>
#include<iomanip>
using namespace std;
class Point{
private:
double x;
double y;
public:
Point():x(0),y(0){cout<<setprecision(16)<<"Point : (0, 0) is created."<<endl;}
Point(double a,double b):x(a),y(b){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is created."<<endl;}
Point(double a):x(a),y(1){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is created."<<endl;}
void show();
~Point()
{
cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<") is erased."<<endl;
}
Point(const Point &p)
{
x=p.x;
y=p.y;
cout<<setprecision(16)<<"Point : ("<<p.x<<", "<<p.y<<") is copied."<<endl;
}
};
void Point::show()
{
cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")"<<endl;
}
void showPoint(Point a)
{
a.show();
}
void showPoint(Point a,Point b,Point c)
{
a.show();
b.show();
c.show();
}
int main()
{
char c;
double a, b;
Point q;
while(std::cin>>a>>c>>b)
{
Point p(a, b);
showPoint(p);
}
Point q1(q), q2(1);
showPoint(q1, q2, q);
}
[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem D: 时间类的构造和输出
Problem D: 时间类的构造和输出
Time Limit:3 SecMemory Limit:128 MB
Submit:1964Solved:595
[Submit][Status][Web Board]
Description
封装一个时间类Time,用于时间处理的相关功能,支持以下操作:1. Time::Time(int,int,int)构造方法:传递时分秒的三个参数构造对象。2. Time::showTime()方法:输出“hh:mm:ss”,不足两位的要前面补0。你设计一个时间类Time,使得main()函数能够正确运行。函数调用格式见append.cc。append.cc中已给出main()函数。
Input
输入的第一个整数n,表示有n组测试数据,每组3个整数:hh,mm,ss,分别表示时、分、秒,其值都在合法的时间范围内。
Output
每组测试数据对应一组输出“hh:mm:ss”,不足两位的输出需要前面补0,格式见sample。
Sample Input
5 0 0 1 0 59 59 1 1 1 23 0 0 23 59 59
Sample Output
00:00:01 00:59:59 01:01:01 23:00:00 23:59:59
HINT
输出格式用头文件
setw(w) :设置数据的输出宽度为w个字符
setfill(c):设置用字符c作为填充字符
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream>
#include<iomanip>
using namespace std;
class Time{
private:
int hour;
int minute;
int second;
public:
Time(int,int,int);
void showTime();
};
Time::Time(int h,int m,int s):hour(h),minute(m),second(s){}
void Time::showTime()
{
cout<<setfill('0')<<setw(2)<<hour<<":"<<setfill('0')<<setw(2)<<setfill('0')<<setw(2)<<minute<<":"<<setfill('0')<<setw(2)<<second<<endl;
}
int main()
{
int cases;
cin>>cases;
for(int i = 1; i <= cases; ++i)
{
int hour, minute, second;
cin>>hour>>minute>>second;
Time t(hour, minute, second);
t.showTime();
}
}
[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem E: 时间类的成员读写
Problem E: 时间类的成员读写
Time Limit:3 SecMemory Limit:128 MB
Submit:1785Solved:582
[Submit][Status][Web Board]
Description
封装一个时间类Time,用于时间处理的相关功能,支持以下操作:1. Time::Time()无参构造方法。2. 成员读函数:Time::hour() :返回Time的小时数;Time::minute():返回Time的分钟数;Time::second():返回Time的秒数。3. 成员写函数:Time::hour(int) :传参修改Time的小时数;Time::minute(int):传参修改Time的分钟数;Time::second(int):传参修改Time的秒数。你设计一个时间类Time,使得main()函数能够正确运行。函数调用格式见append.cc。append.cc中已给出main()函数。
Input
输入的第一个整数n,表示有n组测试数据,每组3个整数:hh,mm,ss,分别表示时、分、秒,其值都在合法的时间范围内。
Output
每组测试数据对应一组输出“hh:mm:ss”,不足两位的输出需要前面补0,格式见sample。
Sample Input
5 0 0 1 0 59 59 1 1 1 23 0 0 23 59 59
Sample Output
00:00:01 00:59:59 01:01:01 23:00:00 23:59:59
HINT
输出格式用头文件
setw(w) :设置数据的输出宽度为w个字符
setfill(c):设置用字符c作为填充字符
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<bits/stdc++.h>
using namespace std;
class Time{
int h,m,s;
public:
Time(int a=0,int b=0,int c=0):h(a),m(b),s(c){}
void showTime(){printf("%.2d:%.2d:%.2d\n",h,m,s);}
int hour(int a=-1){if(~a)h=a;return h;}
int minute(int a=-1){if(~a)m=a;return m;}
int second(int a=-1){if(~a)s=a;return s;}
};
int main()
{
Time t;
int cases;
cin>>cases;
for(int i = 1; i <= cases; ++i)
{
int hour, minute, second;
cin>>hour>>minute>>second;
t.hour(hour);
t.minute(minute);
t.second(second);
cout<<setw(2)<<setfill('0')<<t.hour()<<":";
cout<<setw(2)<<setfill('0')<<t.minute()<<":";
cout<<setw(2)<<setfill('0')<<t.second()<<endl;
}
}
[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem F: 一元二次方程类
Problem F: 一元二次方程类
Time Limit:1 SecMemory Limit:128 MB
Submit:651Solved:232
[Submit][Status][Web Board]
Description
定义一个表示一元二次方程的类Equation,该类至少具有以下3个数据成员:a、b和c,用于表示方程“axx + b*x +c = 0”。同时,该类还至少具有以下两个成员函数:
-
void solve():用于求方程的根。
-
void printRoot():用于输出方程的根。
设定:
-
所有输入的a、b、c所生成的方程必定有个2个不同的实根。
-
输出的两个根按照从大到小的顺序输出,两个根之间用一个空格隔开,而且每个根必须且仅能保留2位小数,即使小数部分为0。
-
请根据样例和给出的main()函数定义相应的构造函数。
Input
输入有若干行,每行有3个实数,分别为方程“axx + b*x + c = 0”中的系数a、b、c。
Output
按照题目要求中的设定条件2输出方程的根。
Sample Input
1 3 2
Sample Output
-1.00 -2.00
HINT
可以使用fixed和setprecision()来实现输出固定小数位数的数值。
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
class Equation{
private:
double a;
double b;
double c;
double s1;
double s2;
public:
Equation(double x,double y,double z):a(x),b(y),c(z){}
void solve()
{
s1=(-b+sqrt(b*b-4*a*c))/(2*a);
s2=(-b-sqrt(b*b-4*a*c))/(2*a);
}
void printRoot()
{
cout <<setiosflags(ios::fixed);
cout<<setprecision(2)<<max(s1,s2)<<" "<<min(s1,s2)<<endl;
}
};
int main()
{
double a, b, c;
while (cin>>a>>b>>c)
{
Equation equ(a,b,c);
equ.solve();
equ.printRoot();
}
return 0;
}
[Home](http://www.cnblogs.com/) | [Web Board](http://www.cnblogs.com/bbs.php?cid=2070) | [ProblemSet](http://www.cnblogs.com/contest.php?cid=2070) | [Standing](http://www.cnblogs.com/contestrank.php?cid=2070) | [Status](http://www.cnblogs.com/status.php?cid=2070) | [Statistics](http://www.cnblogs.com/conteststatistics.php?cid=2070) |
Problem G: 整数的封装
Problem G: 整数的封装
Time Limit:1 SecMemory Limit:128 MB
Submit:787Solved:209
[Submit][Status][Web Board]
Description
现在,请编写一个Integer类,将整数封装起来。目前,只需要你来实现最基本的功能:
- 具有2个构造函数:
(1)Integer::Integer(int):根据参数构建一个整数对象。
(2)Integer::Integer(char*, int):根据给定的字符串和进制来构建一个整数对象。
- 具有一个int Integer::getValue()方法,用于返回Integer类中所封装的整数的具体数值。
Input
输入分为多行。
第一行是一个正整数M,表示其后面的M行为M个整数,每行一个整数。
第M+2行是一个正整数N,表示其后有N行。每行由利用一个空格隔开的2部分组成:前半部分是一个字符串,后半部分是该字符串所使用的进制。
注意:
-
所有的输入,均在int类型的表示范围内,且所有的输入均为合法输入。
-
利用0~9和a~z可最大可以表示36进制的数值。
Output
输出为M+N行,每行为一个十进制整数,且输出顺序应与输入顺序相同。
Sample Input
2 999 -1999 4 0111 2 1a 16 z 36 a 16
Sample Output
999 -1999 7 26 35 10
HINT
Append Code
한국어<中文فارسیEnglishไทย
All Copyright Reserved 2010-2011SDUSTOJTEAM
GPL2.02003-2011HUSTOJ ProjectTEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
class Integer{
private:
int val;
public:
Integer(int n):val(n){}
Integer(char*, int);
int getValue()
{
return val;
}
};
Integer::Integer(char* c, int t)
{
int length=strlen(c);
val=0;
int a;
char ch[101];
strcpy(ch,c);
if(ch[0]=='-')
{
for(a=1;a<length;a++)
{
int num;
char tmp=ch[a];
if(tmp>='0'&&tmp<='9')
{
num=tmp-'0';
val=val*t+num;
}
else if(tmp>='a'&&tmp<='z')
{
num=tmp-'a'+10;
val=val*t+num;
}
else if(tmp>='A'&&tmp<='Z')
{
num=tmp-'A'+10;
val=val*t+num;
}
}
val=0-val;
}
else
{
for(a=0;a<length;a++)
{
int num;
char tmp=ch[a];
if(tmp>='0'&&tmp<='9')
{
num=tmp-'0';
val=val*t+num;
}
else if(tmp>='a'&&tmp<='z')
{
num=tmp-'a'+10;
val=val*t+num;
}
else if(tmp>='A'&&tmp<='Z')
{
num=tmp-'A'+10;
val=val*t+num;
}
}
}
}
int main()
{
char str[100];
int numOfData, numOfStr;
int data, i, radix;
cin>>numOfData;
for (i = 0; i < numOfData; i++){
cin>>data;
Integer anInteger(data);
cout<<anInteger.getValue()<<endl;
}
cin>>numOfStr;
for (i = 0; i < numOfStr; i++){
cin>>str>>radix;
Integer anInteger(str,radix);
cout<<anInteger.getValue()<<endl;
}
return 0;
}
原文链接: https://www.cnblogs.com/auto1945837845/p/5513584.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/233686
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!