I got an assignment to be done..
Given a sequence of positive integers. You need to find the number of triples in that sequence. For this problem, (x, y, z) constructs a triple if and only if x + y = z. So, (1, 2, 3) is a triple, where (3, 4, 5) is not.
Input
Each input set starts with a positive integer N. Next few lines contain N positive integers. Input is terminated by EOF.
Output
For each case, print the number of triples in a line.
Constraint
3 <= N <= 5000
Sample Input........................Sample Output
1 2 3 4 5 6......................TRIPLE is equal to 3.
1 2 4 8 16 32....................TRIPLE is equal to 0.
100000000 200000000 100000000....TRIPLE is equal to
1 1 1 2 2........................TRIPLE is equal to 6.
---------------------------------------------------------------------------------------
And i've tried to do this by my own,but until now,this is the farthest that i could figure out :
#include <iostream>
#include <string>
using namespace std;
int main() {
int integers;
int integer;
int x,y,z;
int triple_first=0;
int triple=0;
cout<<"How many integers? (3 to 5000) : ";
cin>>integers;
while(integers<3 || integers>5000){
cout<<"How many integers? (3 to 5000) : ";
cin>>integers;
}
cout<<"Enter the integers: ";
for(int i=1; i<=integers; i++){
cin>>x;
if((..codes...))
{
..........codes......
}
}
cout<<"Triple is equal to "<<triple;
}
I don't know weather it is right or not,but i think maybe it is more likely to be that way..
Please help..TQ :)