贴一下我写过的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 在它的帮助下我们可以非常方便的将一个命令行程序升级成一个图形 ...
随机推荐
- 在腾讯云centOs系统上安装nginx
1.安装nginx 下载:wget http://nginx.org/download/nginx-1.8.1.tar.gz 解压:tar -zxvf nginx-1.8.1.tar.gz 安装编译源 ...
- map中使用await 异步函数
let result=await Promise.all(dataComments.map(async (ele)=>{ return (async ()=>{ let resData= ...
- Objective-C 类型转换
类型转换通常是指变量,从一种类型转换成另外一种类型.例如将一个long类型转换成int类型,变量转换通常 用下面的方式: (type_name) expression 在Objective-C中,我们 ...
- JS 操作内容 操作元素
操作内容:普通元素.innerHTML = "值": 会把标记执行渲染普通元素.innerText = "值": 将值原封不动的展示出来,即使里面有标记 var ...
- HDU 1520 Anniversary party (树形DP,入门)
题意:给一棵树,每个节点都有权值,要求选择部分节点出来,使得权值之和最大,但是每对(父亲,儿子)中最多只能挑一个. 思路: 比较入门的题,每个节点可以选也可以不选.若当前节点选的话,孩子必须全部不选: ...
- codevs 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description You are a mouse that lives in a cage in ...
- ubuntu 16.0安装 hadoop2.8.3
环境:ubuntu 16.0 需要软件:jdk ssh https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/ 2.8.3 安装 jdk并 ...
- java中的堆与栈
Java 中的堆和栈 Java把内存划分成两种:一种是栈内存,一种是堆内存. 在函数中定义的一些基本类型的变量和对象的引用变量都在函数的栈内存中分配 . 当在一段代码块定义一个变量时,Java就在栈中 ...
- stringstream类的简介和用法
一.简介 <sstream>类库定义了三种类:istringstream,ostringstream,stringstream.分别用来进行流的输入,流的输出,输入输出操作.在此演示str ...
- HTML5微信播放全屏问题的解决方法
在ios和安卓手机里的微信下播放视频时,会遇到不少问题,例如需要手动点击,视频才会播放,并且视频会跳出微信框,出现控制条,如果视频不是腾讯视频,播放完毕会出现腾讯视频的广告推送等问题 解决办法:给vi ...