文章标题
来源:互联网 发布:北京电脑编程学校 编辑:程序博客网 时间:2024/06/02 01:37
:-D还没来得及整理的代码(C++)
#include <iostream>#include <iomanip>#include <array>using namespace std;/*const double Pi = 3.14;class Figure{public: Figure(){}; virtual double area() const = 0;};class Circle :public Figure{public: Circle(double myr){ R = myr; } virtual double area() const { return Pi * R * R; }protected: double R;};class Rectangle :public Figure{public: Rectangle(double myr, double myw){ R = myr; W = myw; } virtual double area() const { return R * W; }private: double R; double W;};void func(Figure &a){ cout << a.area() << endl;}int main(){ Circle a(3.0); Rectangle b(2.0, 4.0); cout << "the area of circle is "; func(a); cout << "the area of retangle is "; func(b); return 0;}*//*class Base{public: Base(){}; virtual ~Base() { cout << "Base destructor is called." << endl; }};class Subclass:public Base{public: Subclass(){}; virtual ~Subclass();};Subclass::~Subclass(){ cout << "Subclass destructor is called." << endl;}int main(){ Base *p = new Subclass; delete p; return 0;}*//*class Complex{public: Complex( double r = 0.0, double i = 0.0); Complex operator + (Complex c); Complex operator - (Complex c); void display();private: double real,image;};Complex::Complex( double r, double i){ real = r; image = i;}Complex Complex::operator + (Complex c){ Complex temp; temp.real = real + c.real; temp.image = image + c.image; return temp;}Complex Complex::operator - (Complex c){ Complex temp; temp.real = real - c.real; temp.image = image - c.image; return temp;}void Complex::display(){ if(image < 0) { cout << real << image << "i" << endl; }else { cout << real << "+" << image << "i" << endl; }}int main(){ Complex c1(12.4,13.3),c2(14.4,26.5); Complex c; cout << "c1 = "; c1.display(); cout << "c2 = "; c2.display(); c = c1 + c2; cout << "c1 + c2 = "; c.display(); c = c1 - c2; cout << "c1 - c2 = "; c.display(); return 0;}*//*int main(){ int a[20],i,j; a[0] = a[1] = 1; for(i = 2;i < 20;i++) { a[i] = a[i-1] + a[i - 2]; } for(j = 0;j < 20;j++) { cout << a[j] << "\t" ; if((j+1) % 5 == 0) cout << endl; } return 0;}*//*int b[5]; //全局变量int main(){ int a[5]; //局部变量 static int c[5]; //静态变量 int i; for(i = 0;i < 5;i++) cout << a[i] << " "; cout << endl; for(i = 0;i < 5;i++) cout << b[i] << " "; cout << endl; for(i = 0;i < 5;i++) cout << c[i] << " "; cout << endl; return 0;}*/// 将一个正整数分解到数组中,然后正向和反向输出/*int main(){ int a[11]; int n,i = 0; cout << "请输入一个正整数:" << endl; cin >> n; while(n) { a[i] = n % 10; n /= 10; i++; } cout << "正向输入的结果是:" << endl; for(int j = i-1;j >= 0;j--) { cout << a[j] << " "; } cout << endl; cout << "反向输入的结果是:" << endl; for(int j = 0;j < i;j++) { cout << a[j] << " "; } cout << endl; return 0;}*//*class Myclass{public: Myclass(); Myclass(int,int); Myclass(Myclass &); void print(); const Myclass &operator = (Myclass &);private: int m,n;};Myclass::Myclass():m(5),n(1){ cout << "Default constructor." << endl;}Myclass::Myclass(int i,int j){ m = i; n = j; cout << "Parameter Constructor." << endl;}Myclass::Myclass(Myclass &my){ m = my.m; n = my.n; cout << "Copy constructor." << endl;559}void Myclass::print(){ cout << "m=" << m << ",n=" << n << endl;}const Myclass& Myclass::operator = (Myclass &my){ m = my.n; n = my.m; return *this;}int main(){ Myclass a,b(10,5); Myclass c(b); a.print(); b.print(); c.print(); c = a; c.print(); return 0;}*//*#include <string>int main(){ try{ cout << "This is try block." << endl; int a,b; cout <<"we want to do /, please input two numbers:"; while(cin >> a >> b){ if(b == 0) { throw b; }cout << "the result is " << a/b << endl; } cout << endl;}catch(int ){ cout << "分母不应该为0." << endl;} cout << "这里是try catch的外面" << endl; return 0;}*//*int main(){ try{ cout << "begin" << endl; cout << "1" << endl; string a; cout << "name: " << endl; cin >> a; if(a != "cathy"){ throw string("Julia is nooooo"); } throw int(112); cout << "2" << endl; }catch(int e) { cout << e << endl; cout << "3" << endl; }catch(string e){ cout << e << endl; cout << "4" << endl; } cout << "end" << endl; return 0;}*//*int main(){ string str[5] = {"aads","adsfs","ssfsd","sdfs","sdas"}; string *cp[] = {&str[4],&str[3],&str[2],&str[1],&str[0]}; int i = 0; while(i < 5) { cout << *cp[i] << endl; i++; } return 0;}*///#include <iostream>/*#include <vector>int main(){ vector <int> ivec; ivec.push_back(1); ivec.push_back(2); ivec.push_back(3); ivec.push_back(4); for(vector <int> ::iterator iter = ivec.begin();iter != ivec.end();++iter) { cout << *iter << endl; } return 0;}*//*#include <fstream>#include <iomanip>#include <cstdlib>void outputLine(int , const string &, double);int main(){ ifstream inClientFile ("E:\\query.txt",ios::in); if( !inClientFile ){ cerr << "File could not be opened" << endl; exit ( EXIT_FAILURE ); } int account; string name; double balance; cout << left << setw(10) << "Account" << setw(13) << "Name" << "Balance" << endl << fixed << showpoint; while(inClientFile >> account >> name >> balance) outputLine (account, name, balance); return 0;}void outputLine(int account , const string & name, double balance){ cout << left << setw(10) << account << setw(13) << name << balance << endl;}*///#include <string.h>/*#include <string>using namespace std;int main(){ char input[10000]; int n; while(cin >> input) { n = strlen(input); int temp = 1; for(int i = 0,j = n-1;i<=j;++i,--j) { if(input(i) != input[j]) { temp = 0; break; } } if(temp) { cout << "Yes!" << endl; }else{ cout << "No!" << endl; } } return 0;}*/#include <iostream>#include <string.h>using namespace std;int main(){ string word; cin >> word; int n = word.length(); int count = 0; for (int i = n - 1; i >= 0; i--) { if (word[i] != 0) { count ++; } else { break; } } cout << count ; return 0;}
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- FZU 1911【矩阵快速幂】
- 内部类
- Android网络应用之使用Scoket的Android客户端与TCP服务器的简单交互
- jQuery中html()和text()的区别
- 数据结构-链表
- 文章标题
- 实现字符串循环右移n 位与左移n位(不建立数组,直接用指针)
- Intro Mechine Learning
- USACO-Section2.2 Subset Sums【动态规划】
- 区间dp
- shell脚本下自动发邮箱
- js练习表回顾
- 如何学习SAP HANA
- Command