#include <iostream>
#include<math.h>
using namespace std;
int main()
{  	
    cout<<"===============================\n";
    cout<<"     学号:12335656555         \n     姓名:空间看韩剧         \n     班级:1233         \n     版本:v201312254          \n ";
    cout<<"===============================\n";
	cout<<"    题目:数组排序及字符串处理         \n";
    cout<<"    请选择:               \n    1: 四数排序问题\n    2:最大利息问题      \n";
    cout<<"===============================\n";
	int m;
	cout<<"请输入您的选择1或2\n";
    cin>>m;
	if(m==1)
    {cout<<"四数排序问题\n===============================\n";
	int a,b,c,d;
	int num1 = 1000,num2 = 1000,num3 = 1000,num4 = 1000;
	int tempa,tempb,tempc,tempd,temp;
	int num[24];/*存放所有可能的数的组合*/
	int i = 0,j = 0,k,x = 0;/*对各变量进行类型声明*/
	cout<<"请输入四个互不相同的数:\n"<<endl;/*提示输入四个整数*/
  	cin >>a;
	cin >>b;
	cin >>c;
	cin >>d;
	if(a==b||a==c||a==d||b==c||b==d||c==d)
	cout<<"输入错误\n";/*提示错误输入*/
	else
    {cout<<"所有可能的数的组合为:\n"<<endl;   
	for(i = 0;i<4;i++)    
	{  for(j = 0;j<3;j++)       
		{  while(1)           
			{   num2 = num2/10;                
				if(num2 == 0) num2 = 1000; /*对零特殊考虑*/               
				if(num2!=num1) 
				break; }          
				for(k = 0;k<2;k++)         
				{  while(1)               
					{  	num3 = num3/10;                   
						if(num3 == 0) num3 = 1000;  /*对零特殊考虑*/                  
						if((num3!=num1)&&(num3!= num2))
						{  
							break; 	}                 
				}                
								while(1)                 
			{   num4 = num4/10;                   
				if(num4 == 0) num4 = 1000;  /*对零特殊考虑*/                 
				if((num4!=num1)&&(num4!= num2)&&(num4!= num3))
				{  	
					break; 	}                 
			}               
			tempa = a*num1;                
			tempb = b*num2;               
			tempc = c*num3;               
			tempd = d*num4;               
			num[x] = tempa+tempb+tempc+tempd;/*考虑所有的可能性*/
			 cout<<num[x]<<' '; /*列出所有可能的排列,并输出到屏幕上*/
            if(x%5 == 4) 
		    cout<<"\n"<<endl;/* 使每行输出五个数*/
			x++;   }        
			 }       
		num1 = num1/10;  }    
	 cout<<endl;
	cout<<"\n从小到大排序:\n"<<endl; 
	for(i = 0;i<24;i++)    
	{ for(j = i+1;j<24;j++)        
		{ if(num[i]>num[j])           
			{  	temp = num[i];               
				num[i] = num[j];                
				num[j] = temp;   }            
    	else num[i] = num[i];  }  /*对所有的数进行从小到大排列*/ 
		cout<<num[i]<<' ';   
	    if(i%5 == 4) 
		cout<<"\n"<<endl;   }/*输出排列后的数(每行五个数)*/
	    cout<<endl;
        
	}}	                                                                                                                                                                                                                                    
    if(m==2)/*当输入2时进入第二问利息问题 */
	{cout<<"最大利息问题\n===============================\n";
	int i10,i5,i3,i2,i1,n10,n5,n3,n2,n1;/*第二小题开始,n表示存款次数*/
	float max=0,term,t,MAX;
	cout<<"请输入您的本金:\n";
	cout<<"===============================\n";
	cin>>t;/*输入本金*/ 
	for(i10=0;i10<=(20/10);i10++) /*穷举所有可能的存款方式*/
	for(i5=0;i5<=((20-10*i10)/5);i5++)
	for(i3=0;i3<=((20-10*i10-5*i5)/3);i3++)
	for(i2=0;i2<=((20-10*i10-5*i5-3*i3)/2);i2++)
	{ 	i1=20-10*i10-5*i5-3*i3-2*i2;
  term=t*pow((double)(1+0.0063*12),(double)i1) 
  *pow((double)(1+2*0.0065*12),(double)i2)
  *pow((double)(1+3*0.0068*12),(double)i3) 
  *pow((double)(1+5*0.0073*12),(double)i5) 
  *pow((double)(1+10*0.0080*12),(double)i10);/* 列出所有的存钱组合*/ 
	if(term>max)
	{   max=term;	n1=i1;   n2=i2;   n3=i3;  n5=i5;   n10=i10;   }
	}/*比较得出最优解*/
		MAX=max-t;
		cout<<"为了获得最大利息他应该这样存:\n";
		cout<<" made fixed deposit for 10 year: "<<n10<< "times\n";
		cout<<" made fixed deposit for 5 year: "<<n5 <<"times\n";
		cout<<" made fixed deposit for 3 year: "<<n3 <<"times\n";
		cout<<" made fixed deposit for 2 year: "<<n2 <<"times\n";
		cout<<" made fixed deposit for 1 year: "<<n1 <<"times\n";
		cout<<" 最大利息: "<<MAX<<"\n";/*输出最优存款方式*/
		cout<<"===============================\n";}
	else
		cout<<"输入错误\n";
	return 0; 
}