-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTargetSum.cpp
167 lines (165 loc) · 3.58 KB
/
TargetSum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//int secondlargest(vector<int> v) //part of question
//{ //2 3 5 7 6 1
// int maxindex=0;
// for(int i=0;i<v.size();i++)
// {
// if (v[i] > v[maxindex] )
// {
// maxindex=i;
// }
// }
// return maxindex;
//}
int main()
{
// cout<<"Find the total number of pair in the given array whose sum is equal to given x"<<endl;
//
// vector <int> v(5);
// for(int i=0;i<v.size();i++)
// {
// cin>>v[i];
// }
// int targetsum;
// cout<<"Enter the traget sum:"<<endl;
// cin>>targetsum;
// int count=0; //to count no of pairs
// for(int i=0;i<v.size();i++)
// {
// for(int j=i+1;j<v.size();j++)
// {
// if(v[i]+v[j]==targetsum)
// {
// count++;
// }
// }
// }
// cout<<"The total number of pairs are:"<<count<<endl;
// cout<<"Find the number of triplets whoe sum is ewual to given value of x"<<endl;
// vector<int> v(6);
// for (int i=0;i<v.size();i++)
// {
// cin>>v[i];
// }
// int targetsum;
// cout<<"Enter the target sum:"<<endl;
// cin>>targetsum;
//
// //for output
// int count=0;
// for (int i=0;i<v.size();i++)
// {
// for(int j=i+1; j<v.size(); j++)
// {
// for (int k=j+1; k<v.size(); k++)
// {
// if(v[i]+v[j]+v[k]==targetsum)
// {
// count++;
// }
// }
// }
// }
// cout<<"The total numbers of pairs are:"<<count<<endl;
//
// cout<<"Find the unique number in the array where all the elements are being repeated twice with one value being unique"<<endl;
// vector<int> v(7);
// for(int i=0;i<v.size();i++)
// {
// cin>>v[i];
// }
//
// for (int i=0;i<v.size();i++) //to compare the values
// {
// for(int j=i+1;j<v.size();j++)
// {
// if(v[i]==v[j])
// {
// v[i]=v[j]=-1; //pass the -1 at index where value compare is same.
// }
// }
// }
// for(int i=0; i<v.size(); i++)
// {
// if(v[i] !=-1)
// {
// cout<<"The unique value that is not twice is:"<<v[i]<<" ";
// }
// }
// for (int i=0;i<v.size();i++)
// {cout<<"Find the sexond largest element i the array/vector"<<endl;
// vector<int> v(6);
// for(int i=0;i<v.size();i++)
// {
// cin>>v[i];
// }
//
// int largestElement=secondlargest(v);
//// v[largestElement]=-1;
// int Lelement=v[largestElement];
// for(int i=0;i<v.size();i++)
// {
// if(v[i]==Lelement)
// {
// v[i]=-1;
// }
// }
// int secondlargestElment=secondlargest(v);
// cout<<"The second largest ele is:"<<v[secondlargestElment]<<endl;
// cout<<"Enter size:"<<endl;
// int n;
// cin>>n;
//
// cout<<"Rotate a given array n by k step where k is non negative integers note k can be greater then n as n is zie of arraya:"<<endl;
// vector<int> v(n);
// for(int i=0;i<v.size();i++)
// {
// cin>>v[i];
// }
// int k;
// cout<<"Enter your k step:"<<endl;
// cin>>k;
//
// k=k%5; //becauce k can be greater then n and after 5 step we are getting back again same array.
//
// int newarray[5];
// int j=0;
// for(int i=n-k;i<v.size();i++) //
// {
// newarray[j++]=v[i];
// }
// for (int i=0;i<=k;i++)
// {
// newarray[j++]=v[i];
// }
//
// //for output
// for(int i=0;i<5;i++)
// {
// cout<<newarray[i]<<" ";
// }
// int n;
// cin>>n;
// cout<<"Rotate a given array n by k step where k is non negative integers note k can be greater then n as n is zie of arraya:"<<endl;
// vector<int> v(n);
// for(int i=0;i<n;i++)
// {
// cin>>v[i];
// }
// int k;
// cout<<"Enter your k step:"<<endl;
// cin>>k;
// k=k%v.size(); //becauce k can be greater then n and after 5 step we are getting back again same array.
//
// reverse (v.begin(), v.end());
// reverse (v.begin(),v.begin()+k);
// reverse (v.begin()+k,v.end());
//
// for(int i=0;i<v.size();i++)
// {
// cout<<v[i]<<" ";
// }
}