Commit 15c20b067983165fa1bd822dc3817185d4828805
1 parent
fe366b26f8
Exists in
main
Create Teste.
Showing 5 changed files with 86 additions and 0 deletions Side-by-side Diff
.idea/.gitignore
View file @
15c20b0
.idea/Competitive-Programming.iml
View file @
15c20b0
.idea/modules.xml
View file @
15c20b0
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<project version="4"> | |
3 | + <component name="ProjectModuleManager"> | |
4 | + <modules> | |
5 | + <module fileurl="file://$PROJECT_DIR$/.idea/Competitive-Programming.iml" filepath="$PROJECT_DIR$/.idea/Competitive-Programming.iml" /> | |
6 | + </modules> | |
7 | + </component> | |
8 | +</project> |
.idea/vcs.xml
View file @
15c20b0
BasicsOfArrayStringGreedyandBitManipulation/ReverseAnArray/Problem2/ReverseAnArray.cpp
View file @
15c20b0
1 | +// | |
2 | +// Created by ronal on 2/11/2023. | |
3 | +// Problem description link. | |
4 | +// | |
5 | + | |
6 | +#include <iostream> | |
7 | +#include <vector> | |
8 | +using namespace std; | |
9 | + | |
10 | +void inverter(vector<int> &V){ | |
11 | + int start = 0; | |
12 | + int end = V.size() - 1; | |
13 | + | |
14 | + while(start < end){ | |
15 | + int tmp = V[start]; | |
16 | + V[start] = V[end]; | |
17 | + V[end] = tmp; | |
18 | + start++; | |
19 | + end--; | |
20 | + } | |
21 | +} | |
22 | + | |
23 | +int SumReverse(vector<int> V){ | |
24 | + int sum = 0; | |
25 | + int square = 0; | |
26 | + for(int i = 0; i < V.size(); i++){ | |
27 | + square = V[i]*V[i]; | |
28 | + if( i % 2 == 0){ | |
29 | + sum += square; | |
30 | + }else{ | |
31 | + sum -= square; | |
32 | + } | |
33 | + } | |
34 | + return sum; | |
35 | +} | |
36 | +int main() { | |
37 | + | |
38 | + vector<int> V; | |
39 | + int tests, size, value; | |
40 | + cin >> tests; | |
41 | + | |
42 | + for(int i = 0; i < tests; i++){ | |
43 | + cin >> size; | |
44 | + for(int j = 0; j < size; j++){ | |
45 | + cin >> value; | |
46 | + V.push_back(value); | |
47 | + } | |
48 | + inverter(V); | |
49 | + cout << SumReverse(V) << "\n"; | |
50 | + V.clear(); | |
51 | + } | |
52 | + | |
53 | + | |
54 | + | |
55 | + return 0; | |
56 | +} |