#pragma once #include<iostream> using std::cout; using std::endl; template<typename T> class Vector { public: Vector(T n) :size(n) { p = new T[n]; } Vector(T n, T value) :size(n) { p = new T[n]; for (int i = 0; i < n; i++) p[i] = value; } Vector(const Vector& V):size{V.size} { p = new T[V.size]; for (int i = 0; i < V.size; i++) p[i] = V.p[i]; } ~Vector() { delete[]p; } T get_size() { return size; } T &at(int i) { return p[i]; } T& operator[](int i) { return p[i]; } friend void output(Vector& V) { for (int i = 0; i < V.size; i++) { cout << V.p[i]<<" "; } cout << endl; } private: T size; T* p; };
修改数据后
#include<iostream> #include <fstream> #include<string> #include<iomanip> using namespace std; void output(std::ostream& out) { string a[27][27] = { " " }; int n = 0; for (int i = 1; i < 27; i++) { a[i][0] = to_string(i); a[0][i] = 97 + n; n++; } for (int i = 1; i < 27; i++) { n = i; for (int j = 1; j < 27; j++) { if (65 + n > 90) { a[i][j] = 65 + n - 26; } else { a[i][j] = 65 + n; } n++; } } for (int i = 0; i < 27; i++) { for (int j = 0; j < 27; j++) { out <<right<< setw(2) << a[i][j] << " "; } out << endl; } } int main() { ofstream out; out.open("cipher_key.txt", ios::out); if (!out.is_open()) { cout << "fail to open file\n"; return 1; } output(out); output(cout); out.close(); }
标签:27,int,++,Vector,实验,include,size From: https://www.cnblogs.com/030227rzxx/p/16960332.html