当前位置:网站首页>Vector 3 (static member)
Vector 3 (static member)
2022-06-23 01:04:00 【SZU healing system bug】
Catalog
Title Description
Vector 1 Topic realization CVector Class to add private static members sum, While initializing the object , Statistics of all objects n Dimensional vector sum sum.
The main function generates multiple objects , Test vectors and .
You can add static member functions as needed , Adding non static member functions does not score .
Input
Number of tests t
The format of each group of test data is as follows :
Input m, Express n The number of dimensional vectors
Heel m That's ok , Format per line : Vector dimension n n Dimension vector values
Output
Of each set of test data m Vector , Output the sum of the components of all vectors sum
sample input 1
2
2
5 1 2 3 4 5
3 4 5 6
3
2 1 2
3 10 20 30
2 11 22
sample output 1
1 2 3 4 5
4 5 6
30
1 2
10 20 30
11 22
96
AC Code
#include<iostream>
using namespace std;
class CVector
{
int * data;
int n;
static int sum;
public:
CVector(){
data=new int[5];
for(int i=0;i<5;i++)
{
data[i]=i;
sum+=i;
}
n=5;
}
CVector(int n1,int *a){
n=n1;
data=new int[n1];
for(int i=0;i<n1;i++)
{
data[i]=a[i];
sum+=a[i];
}
}
void display(){
int i;
for(i=0;i<n-1;i++)
cout<<data[i]<<' ';
cout<<data[i]<<endl;
}
static int getsum(){return sum;}
static void setsum(){sum=0;}
~CVector(){
if(data)
delete[] data;
data=NULL;
}
};
int CVector::sum=0;
int main() {
int n,i,t,m;
cin>>t;
while(t--)
{
CVector::setsum();
cin>>m;
while(m--)
{
cin>>n;
int *p=new int [n];
for(i=0;i<n;i++)
cin>>p[i];
CVector b(n,p);
b.display();
if(p)
delete[] p;
p=NULL;
}
cout<<CVector::getsum()<<endl;
}
}边栏推荐
- Typecho imitation of Lu Songsong's blog theme template / Technology Information blog theme template
- Using geTx to build a more elegant structure of flutter pages
- Database daily question - day 20: selling products by date
- 黄金etf持仓量如何算
- TiDB VS MySQL
- SAP ui5 application development tutorial 102 - detailed trial version of print function implementation of SAP ui5 application
- How Huawei cloud implements a global low delay network architecture for real-time audio and video [Part 1]
- 关于测试/开发程序员技术的一些思考,水平很高超的,混不下去了......
- SAP ui5 application development tutorial 103 - how to consume the trial version of the third-party library in SAP ui5 applications
- Psychological analysis of the safest spot Silver
猜你喜欢

SAP ui5 application development tutorial 103 - how to consume the trial version of the third-party library in SAP ui5 applications

Cadence spb17.4 - Allegro - optimiser la spécification de l'angle de connexion de la polyligne pour une seule ligne électrique - polyligne à arc

SAP ui5 application development tutorial 103 - how to consume third-party libraries in SAP ui5 applications

EasyCVR硬件盒子如何设置断电自启动

Explain the startup process of opengauss multithreading architecture in detail

What is the storage structure and mode of data in the database?

BGP federal comprehensive experiment

MGRE环境下的OSPF实验

SAP MM 事务代码VL04为STO创建外向交货单

3DMAX modeling notes (I): introducing 3DMAX and creating the first model Hello World
随机推荐
使用aggregation API扩展你的kubernetes API
2022 TIANTI match - National Finals rematch
Some thoughts about the technology of test / development programmers are very advanced, and they can't go on
Introduction to the use of opencvsharp (C openCV) wechat QRcode decoding function (with source code attached)
TiDB VS MySQL
Shell 查看帮助
Prevent others from using the browser to debug
Explain the startup process of opengauss multithreading architecture in detail
Typecho imitation of Lu Songsong's blog theme template / Technology Information blog theme template
Read Amazon memorydb database based on redis
SAP ui5 application development tutorial 103 - how to consume the trial version of the third-party library in SAP ui5 applications
How about China International Futures Co., Ltd.? Is it a regular futures company? Is it safe to open an account online?
SAP ui5 application development tutorial 102 - detailed trial version of print function implementation of SAP ui5 application
JMeter associated login 302 type interface
LINQ 查询
SAP UI5 应用开发教程之一百零二 - SAP UI5 应用的打印(Print)功能实现详解
Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines
Dig three feet to solve the data consistency problem between redis and MySQL
Which brokerage platform is better and safer for a brokerage to open an account on a mobile phone? What if you need a low commission
你踩过这些坑吗?谨慎在时间类型列上创建索引