删除数组中的重复元素 买卖股票的最高利润 爬楼梯

第一题:

#include "stdafx.h"

#include<iostream>

using namespace std;

int main()

{

 int shu[10];

 int i;

 for (i = 0; i < 10; i++)

 {

  cin >> shu[i];

 }

 int j,h, k = 0;

 for(int n=1;n<10;n++)

 {

  for (j = 0; j < 10; j++)

 

  if (shu[j] == shu[j + n])

  {        

shu[j] = shu[j + 1];    k++;   

}   

 }

 cout << "新数组的长度为:" << 10 - k;

 for (int m = 0; m <(10 - k); m++)

 {  

 cout << "新的数组的元素为:" << shu[m];

 }  

   return 0;

}

第二题:

#include "stdafx.h"

#include<iostream>

using namespace std;

int main()

{

 double shu[20];

 int i;  

for (i = 0; i < 20; i++)

 {   cin >> shu[i];  

}  int j;

 int h = 0;  

for(int n=1;n<20;n++)

 {

  for (j = 0; j < 19; j++)

  {  

  int m = shu[j + n] - shu[j];    

if (m > h)  

  {     h = m;    }

  }

 }

 cout << "利润最大为:" << h;  

   return 0;

}

第三题:

#include "stdafx.h"

#include<iostream>

using namespace std;

int s(int n)

{

 if (n == 1)  

{  

 return 1;

 }

 else   if (n == 2)  

 {   

 return 2;  

 }  

 else  

  return s(n - 1) + s(n - 2);

}

int main()

{

 int n;

 cin >> n;

 s(n);

 return s(n);

}

 

posted @ 2017-03-09 17:28  祝海霞  阅读(99)  评论(0编辑  收藏  举报