Write a method that uses a divide-and-conquer strategy to find the maximum value
ID: 3739367 • Letter: W
Question
Write a method that uses a divide-and-conquer strategy to find the maximum value in an integer array. The maximum value of a one-element array is that element. The maximum of any other array is the maximum of the left half, or the maximum of the right half, whichever is larger. (You can use ArraySum as a starting point.)
How many balls are in this pyramid?
Each level in the pyramid is a square, so if there are n levels, the bottom level has n * n balls, and the total number of balls is just
(n * n) + (number of balls in a pyramid of height n - 1).
There is just one ball in a pyramid of height 1. Write a static recursive method getPyramidCount that takes a single intargument representing the number of levels in a pyramid, and returns the total number of balls.
Explanation / Answer
ANS:-
void fill(){
while(true){
cin>>symbol;
if(symbol=='E'){
cout<<"type s to save"<<endl;
save();
}
else{
cout<<"type E to exit and F to continue fill"<<endl;
cout<<"Load text:";
cin>>filename;
std::ifstream infile(filename,std::ofstream::binary);
std::ofstream outfile ("temp.txt",std::ofstream::binary);
outfile.open ("test.txt");
cout<<"Enter x co-ordinate:";
cin>>x;
cout<<"Enter y co-ordinate:";
cin>>y;
cout<<"Enter symbol:";
cin>>symbol;
string line;
while (std::getline(infile, line)){
if(x==0)
break;
outfile.write(line,line.length());
x--;
}
if(x==0 and line.length()>0){
line[y-1]=symbol;
outfile.write(line,line.length());
while (std::getline(infile, line)){
outfile.write(line,line.length());
}
}
else{
while(x>0){
outfile.write(" ",1);
}
line='';
for(int i=0;i<y;i++){
line+=' ';
}
line[y-1]=symbol;
outfile.write(line+" ",line.length());
}
outfile.close();
infile.close();
std::ofstream file;
file.open(filename,ios::out);
std::ifstream infile("new.txt",std::ofstream::binary);
while (std::getline(infile, line)){
file.write(line,line.length());
}
file.close();
infile.close();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.