贴一下我写过的c++程序代码
5258
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class X{
public:
const static double PI;
};
const double X::PI=acos(-1.0);
int main()
{
cout<<setiosflags(ios::fixed)<<setprecision(2)<<X::PI<<endl;
return 0;
}
1178
#include<iostream>
#include<string>
using namespace std;
int main(){
string c;
int count=0;
while (cin >> c)
{ count++; }
cout << count << endl;
return 0;
}
1001
#include <iostream.h>
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
1174
#include<iostream>
#include<string>
using namespace std;
int main(){
string s, c;
getline(cin, s);
cin >> c;
int pos = 0;
while ((pos=s.find(c, pos) )>= 0)
s.erase(pos, c.length());
cout << s << endl;
return 0;}
1283使用优先队列来一波
#include <stdio.h>
#include <queue>
using namespace std;
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
priority_queue<int,vector<int>,greater<int> > qu;
for(int i=0; i<n; i++) {
int a;
scanf("%d",&a);
qu.push(a);
}
printf("%d",qu.top());
for(int i=1; i<n; i++) {
qu.pop();
printf(" %d",qu.top());
}
printf("\n");
}
return 0;
}
1090使用sort来一波,使用c++写起来好麻烦,不过这个更安全
#include <bits/stdc++.h>
using namespace std;
int cmp(int a,int b){
return fabs(a)>fabs(b);}
int main()
{int n,j,i,t;
while(cin>>n,n)
{vector<int>a;
for(i=0;i<n;i++){
int p;
cin>>p;
a.push_back(p);}
sort(a.begin(),a.end(),cmp);
vector<int> :: iterator it;
it=a.begin();
cout<<*it;
it++;
for(;it!=a.end();it++)
cout<<" "<<*it;
cout<<endl;
}
return 0;}
1214就是个简单的操作
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
vector<int>a;
string s;
int i,j,x,y,;
while(getline(cin,s))
{
if(s=="clear")
{
a.clear();
}
else if(s=="delete")
{
cin>>x;
cout<<a[x-1]<<endl;
a.erase(a.begin()+x-1);
}
else if(s=="insert")
{
cin>>j;
while(j--)
{
cin>>x>>y;
a.insert(a.begin()+x-1,y);
}
}
else if(s=="getelem")
{
cin>>x;
cout<<a[x-1]<<endl;
}
else if(s=="exit")
return 0;
}
}
1171字符串倒置,直接放进函数就ok
#include <bits/stdc++.h>
using namespace std;
int main()
{string s;
getline(cin,s);
reverse(s.begin(),s.end());
cout<<s<<endl;
return 0;}
3016设计一个简单的类
#include <iostream>
#include <cmath>
class CPoint
{
private:
double x;
double y;
public:
void setXY(double x, double y);
double returnx() { return x; }
double returny() { return y; }
};
class Circle
{
private:
double r;
public:
CPoint center;
double Dist(Circle p);
double setR(double r);
double relation(double d, Circle c2);
};
double Circle::Dist(Circle p)
{
double d;
d = sqrt((this->center.returnx() - p.center.returnx())*(this->center.returnx() - p.center.returnx()) + (this->center.returny() - p.center.returny())*(this->center.returny() - p.center.returny()));
return d;
}
double Circle::setR(double r)
{
this->r = r;
return 0;
}
double Circle::relation(double l, Circle b)
{
if (l > r + b.r)
return 2;
else if (l == r + b.r || l == fabs(r - b.r))
return 1;
else if (l<r + b.r&&l>fabs(r - b.r))
return 4;
else
return 3;
}
void CPoint::setXY(double x, double y)
{
this->x = x;
this->y = y;
}
using namespace std;
int main()
{
double x1, x2, y1, y2, r1, r2;
Circle c1, c2;
while (cin >> x1 >> y1 >> r1)
{
cin >> x2 >> y2 >> r2;
c1.center.setXY(x1, y1);
c2.center.setXY(x2, y2);
c1.setR(r1);
c2.setR(r2);
double d = c1.Dist(c2);
double back;
back = c1.relation(d, c2);
cout << back << endl;
}
}
3846
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class CTriangle{
private:
int a,b,c;
public:
void Init(int a,int b,int c);
double Area();
};
void CTriangle::Init(int a,int b,int c){
this->a=a;
this->b=b;
this->c=c;
}
double CTriangle::Area(){
double l=(a+b+c)/2.0;
return sqrt(l*(l-a)*(l-b)*(l-c));
}
5232写构造函数析构函数什么的
#include <iostream>
using namespace std;
class X{
public:
X(){
puts("Constructor");
}
~X(){
puts("Destructor");
}
};
int main()
{
X x[3];
return 0;
}
#include<iostream>
using namespace std;
class X{
private:
int b;
public:
X(int a){
b=a;
printf("Constructor %d\n",b);
}
X(X &Y){
b=Y.b;
printf("Copy Constructor %d\n",b);
}
~X(){
puts("Destructor");
}
};
5233
#include <iostream>
using namespace std;
class X{
public:
X(){
puts("Constructor");
}
~X(){
puts("Destructor");
}
};
5234
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class CPoint{
public:
double x,y;
CPoint(double x,double y){
this->x=x;
this->y=y;
}
double Dist(CPoint p){
double d;
d=sqrt((this->x - p.x)*(this->x - p.x) + (this->y - p.y)*(this->y - p.y));
return d;}
};
5236
#include<iostream>
using namespace std;
class X{
private:
int b;
public:
X(int a){
b=a;
printf("Constructor %d\n",b);
}
X(X &Y){
b=Y.b;
printf("Copy Constructor %d\n",b);
}
~X(){
puts("Destructor");
}
};
5251
#include <iostream>
using namespace std;
class Point{
public:
int x,y;
Point(int x,int y){
this->x=x;
this->y=y;
}
};
class Circle{
private:int x,y,r;
public:Circle(Point a,int r){
this->r=r;
this->x=a.x;
this->y=a.y;
}
int Contain(Point a){
if((a.x-x)*(a.x-x)+(a.y-y)*(a.y-y)<r*r)
return 1;
else return 0;
}
};
贴一下我写过的c++程序代码的更多相关文章
- 4.写一个控制台应用程序,接收一个长度大于3的字符串,完成下列功能: 1)输出字符串的长度。 2)输出字符串中第一个出现字母a的位置。 3)在字符串的第3个字符后面插入子串“hello”,输出新字符串。 4)将字符串“hello”替换为“me”,输出新字符串。 5)以字符“m”为分隔符,将字符串分离,并输出分离后的字符串。 */
namespace test4 {/* 4.写一个控制台应用程序,接收一个长度大于3的字符串,完成下列功能: 1)输出字符串的长度. 2)输出字符串中第一个出现字母a的位置. 3)在字符串的第3个字符 ...
- Spring写第一个应用程序
ref:http://www.importnew.com/13246.html 让我们用Spring来写第一个应用程序吧. 完成这一章要求: 熟悉Java语言 设置好Spring的环境 熟悉简单的Ec ...
- 用python写一个定时提醒程序
身体是革命的本钱,身体健康了我们才有更多精力做自己想做的事情,追求女神,追求梦想.然而程序员是一个苦比的职业,大部分时间都对着电脑,我现在颈椎就不好了,有时候眼睛还疼,我还没20阿,伤心...于是乎写 ...
- 干净win7要做几步才能运行第一个Spring MVC 写的动态web程序
干净win7要做几步才能运行第一个Spring MVC 写的动态web程序: 1. 下载安装jdk 2. 配置Java环境变量 3. 测试一下第1,2两步是否完全成功:http://jingyan.b ...
- 请写出一段JavaScript代码,要求页面有一个按钮,点击按钮弹出确认框。程序可以判断出用
请写出一段JavaScript代码,要求页面有一个按钮,点击按钮弹出确认框.程序可以判断出用 户点击的是“确认”还是“取消”. 解答: <HTML> <HEAD> <TI ...
- 五月的仓颉大神写的 三年java程序员面试感悟 值得分享给大家
感谢 五月的仓颉 的这篇文章 , 让我重新认识到自己身上的不足之处 . 原文地址http://www.cnblogs.com/xrq730/p/5260294.html,转载请注明出处,谢谢! 前 ...
- python学习(10)字典学习,写一个三级菜单程序
学习了字典的应用.按老师的要求写一个三级菜单程序. 三级菜单程序需求如下: 1.深圳市的区--街道--社区---小区4级 2.建立一个字典,把各级区域都装进字典里 3.用户可以从1级进入2级再进入3级 ...
- C++代写,代写C++,C++程序代写,C++ assignment代写
C++代写,代写C++,C++程序代写 关于C++代写,我们的涉猎范围: C++数据结构.算法题目 C++操作系统os题目 C++网络编程networking题目 C++ Linux题目 C++ Wi ...
- 手写笔记变PDF-几行代码变命令行程序为图形化界面
前言 最近发现了一个非常不错的Python类库----Gooey, https://github.com/chriskiehl/Gooey 在它的帮助下我们可以非常方便的将一个命令行程序升级成一个图形 ...
随机推荐
- 一文带你读懂 Mysql 和 InnoDB存储引擎
作为一名开发人员,在日常的工作中会难以避免地接触到数据库,无论是基于文件的 sqlite 还是工程上使用非常广泛的 MySQL.PostgreSQL,但是一直以来也没有对数据库有一个非常清晰并且成体系 ...
- 这么大一座Azure“图书馆”,你竟没有发现…
为避免被叫做「伸手党」,很多技术人员早已养成遇到问题上网搜的好习惯. 然而…… 同一个概念,搜到两个相互矛盾的解释,以谁的为准? 想查找某个 API 的用法,搜索结果数十万条,怎样筛选出最有价值的? ...
- asp.net 页面嵌套(非iframe)方法
前台 <div id="divUrlDetail" runat="server"> </div> 后台 protected void P ...
- java 核心技术卷一笔记 6 .2.3 接口 lambda 表达式 内部类
6.2.3 对象克隆 Cloneable 接口,这个接口指示一个类提供了一个安全的clone方法.(稍作了解) 为一个对象引用的变量建立副本时,原变量和副本都是同一个对象的引用,任何一个变量改变都 ...
- 第八篇:cx_Oracle出现的问题
1.cx_Oracle.DatabaseError: ORA-24315: illegal attribute type 2.cx_Oracle.InterfaceError: Unable to a ...
- Linux文件的IO操作 一
系统调用 系统调用: 操作系统提供给用户程序调用的一组“特殊”接口,用户程序可以通过这组“特殊”接口来获得操作系统内核提供的服务 为什么用户程序不能直接访问系统内核提供的服务 为了更好地保护内核空间, ...
- java程序-类的高级特性
创建Employee类,在类中定义三个属性:编号,姓名,年龄,然后在构造方法里初始化这三个属性,最后在实现接口中的定义的CompareTo方法,将对象按编号升序排列. 代码如下:(程序可能有些错误,方 ...
- EF关于报错Self referencing loop detected with type的原因以及解决办法
1)具体报错 { "Message": "出现错误.", "ExceptionMessage": "“ObjectContent` ...
- Python基础篇 -- 字符串
字符串 字符串是不可变的对象,任何操作对原字符串是不会有任何影响的. 索引和切片 索引 . 索引就是下标, 下标从 0 开始, 使用[] 来获取数据 s1 = "0123456" ...
- common-fileupload上传文件
文件上传在web应用中非常普遍,要在jsp环境中实现文件上传功能是非常容易的,因为网上有许多用java开发的文件上传组件,本文以commons-fileupload组件为例,为jsp应用添加文件上传功 ...