Advertisement
benyeh

Untitled

Apr 8th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int arr[1000];
  9.  
  10. void clear(){
  11.     for(int i = 0; i < 1000; i++){
  12.             arr[i] = 0;
  13.     }
  14. }
  15.  
  16. int getMaxHeight(int xmin, int xmax){
  17.     int h = arr[xmin];
  18.     for(int i = xmin+1; i < xmax; i++){
  19.         if(arr[i] > h){
  20.             h = arr[i];
  21.         }
  22.     }
  23.     return h;
  24. }
  25. int main() {
  26.     string fname, line;
  27.     cin >> fname;
  28.     ifstream inputFile(fname.c_str());
  29.     int t, b, xmin, xmax, h, maxh, ht;
  30.     inputFile >> t;
  31.     for(int i = 0; i < t; i++){
  32.         clear();
  33.         //cout << t << endl;
  34.         inputFile >> b;
  35.         //cout << b << endl;
  36.         for(int i = 0; i < b; i++){
  37.             inputFile >> xmin;
  38.             inputFile >> xmax;
  39.             inputFile >> h;
  40.             maxh = getMaxHeight(xmin, xmax);
  41.             //cout << xmin << " " << xmax << " " << h << " " << maxh << endl;
  42.             for(int j = xmin; j < xmax; j++){
  43.                 arr[j] = maxh+h;
  44.             }
  45.         }
  46.  
  47.         // search contour
  48.         int prevHeight = 0, prevXmin = 0;
  49.         cout << "(0,0) ";
  50.         for(int i = 0; i < 1000; i++){
  51.             if(arr[i] != prevHeight){
  52.                 cout << "(" <<  i << "," << prevHeight << ") " ;
  53.                 cout << "(" <<  i << "," << arr[i] << ") " ;
  54.             }
  55.             prevHeight = arr[i];
  56.             prevXmin = i;
  57.         }
  58.         cout << "(1000,0)" << endl;
  59.     }
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement