Paste the C + + program code I've written

Source: Internet
Author: User

5258

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace Std;
Class x{
Public
const static double PI;
};
Const DOUBLE X::P I=acos (-1.0);
int main ()
{
Cout<<setiosflags (ios::fixed) <<setprecision (2) <<x::P i<<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 use priority queue for a wave

#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 using sort for a wave, using C + + to write a good trouble, but this is more secure

#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 is a simple operation.

#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 string inversion, put directly into the function is 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 Designing a simple class

#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::D ist (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 write constructor destructors or something

#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;
}
};

Paste the C + + program code I've written

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.