复习基础算法。
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
//正余弦弧度转度数
#define TRANS(x) (x/180.0*acos(-1.0))
int main()
{
// cout<<1+2<<endl;
// cout<<3-4<<endl;
// cout<<8/4<<endl;
// double result=0.12345678;
// result = 8.0/3;
// cout<<result<<endl;
// cout.setf(ios::showpoint); //打印小数点
// cout.setf(ios::fixed);
// cout<<setprecision(0)<<result<<endl;
// cout<<setprecision(1)<<result<<endl;
// cout<<setprecision(2)<<result<<endl;
// cout<<setprecision(3)<<result<<endl;
// cout<<setprecision(4)<<result<<endl;
// cout<<setprecision(5)<<result<<endl;
//
// 设置域宽
// cout<<setw(10)<<setiosflags(ios::left)<<setfill('*')<<10<<endl;
// cout<<setw(10)<<setiosflags(ios::right)<<setfill('*')<<10<<endl;
// cout<<setw(10)<<setfill('*')<<10<<endl;
// int a=10;
// int b=20;
// cout.setf(ios::right,ios::adjustfield);
// cout.fill('0');
// cout << setw(6) << a <<endl;
// cout << setw(6) << b << endl;
// double result = 8.0/5;
// cout.setf(ios::fixed); //保留固定的小数点后的位数
// cout.setf(ios::showpoint);
// cout<<setprecision(1)<<result<<endl;
//1-1圆柱体的表面积
/* double r, h;
const double pi = acos(-1.0);
double result;
cin>>r>>h;
result = 2*r*pi*h+2*pi*r*r;
cout.setf(ios::fixed);
cout<<setprecision(3)<<result<<endl;
*/
//1-6 三位数反转(1)
/* int num,a,b,c;
int d = 0;
int result;
cin>>num;
//法一
a = num%10;
b = num/10%10;
c = num/100;
cout<<a<<b<<c;
//1-7 法二
result = (num%10)*100 + (num/10%10)*10 + (num/100);
printf("%03d",result);
*/
//1-3 交换变量
// int a,b,temp=0;
// cin>>a>>b;
// cout<<b<<' '<<a;
/* temp = a;
a = b;
b = temp;
cout<<a<<' '<<b;
*/
//鸡兔同笼 ,鸡两只腿,兔子四只腿
/* int n,m; //总数,总腿数
int a,b; //鸡数量,兔子数量
cin>>n>>m;
//现在有n只鸡兔, 共m只腿
// b = (m - 2*n)/2;
// a = n - a;
a = (4*n - m)/2;
b = n - a;
if(m%2 == 1 || a<0 || b<0)
cout<<"No answer"<<endl;
else
cout<<a<<' '<<b;
*/
//三整数排序
// int a,b,c,t;
// cin>>a>>b>>c;
// if(a>b && a>c && b>c)
// cout<<c<<' '<<b<<' '<<a;
// else if(a>b && a>c && c>b)
// cout<<b<<' '<<c<<' '<<a;
// else if(b>a && b>c && a>c)
// cout<<c<<' '<<a<<' '<<b;
// else if(b>a && b>c && c>a)
// cout<<a<<' '<<c<<' '<<b;
// else if(c>a && c>b && a>b)
// cout<<b<<' '<<a<<' '<<c;
// else if(c>a && c>b && b>a)
// cout<<a<<' '<<b<<' '<<c;
//
/* if(a>b) {
t = a;
a = b;
b = t;
}
if(a>c) {
t = a;
a = c;
c = t;
}
if(b>c) {
t = b;
b = c;
c = t;
}
cout<<a<<' '<<b<<' '<<c;
*/
//1-1 平均数
/*
double a,b,c;
double result=0.0;
cin>>a>>b>>c;
result = (a+b+c)/3;
cout.setf(ios::fixed);
cout<<setprecision(3)<<result;
*/
//1-2 连续和
/* int n,num=0;
cin>>n;
for(int i=n; i>0; i--)
{
num = num + i;
}
cout<<num; //1.723s
*/
/* int n;
cin>>n;
cout<<n*(n+1)/2<<endl; //2.432s
*/
//1-4 正弦和余弦
//cos和sin都是使用弧度制,所以要转化为角度制
// int n;
// cin>>n;
// cout.setf(ios::fixed);
// cout<<setprecision(5)<<sin(TRANS(n));
// printf("%lf %lf",sin(TRANS(n)), cos(TRANS(n)));
//1-5 打折
/* int m,n = 95;
double result=0.0;
cin>>m;
result = m*n;
if(result>=300)
{
result = result * 0.85;
} else {
cout<<result;
}
cout.setf(ios::fixed);
cout<<setprecision(2)<<result;
*/
//1-6 三角形
/* int a,b,c;
cin>>a>>b>>c;
if(a>b && a>c && a*a==(b*b+c*c))
cout<<"yes";
else if(b>a && b>c && b*b==(a*a+c*c))
cout<<"yes";
else if(c>a && c>b && c*c==(a*a+b*b))
cout<<"yes";
else
cout<<"not a trangle";
*/
//1-7 年份
/* int year;
cin>>year;
if(year%400==0 || year%4==0 && year%100!=0)
cout<<"是闰年";
else
cout<<"不是闰年";
*/
//1-8 思考题
//1. int整数类型的最大值和最小值 INT_MAX INT_MIN
/* int n=0,i=0;
while(n>=i){
n = i;
i--;
}
cout<<"最小值:"<<n<<endl;
while(n<=i){
n = i;
i++;
}
cout<<"最大值:"<<n<<endl;
system("pause");
//输出结果为 最小值:-2147483648 最大值:2147483647
*/
//2.
//double型浮点数能精确到多少位小数?
//double型浮点数实际精度为15~16位,即能精确到15~16位有效数字
//double型浮点数最大正数值和最小正数值分别是-2^1024~2^1024,即-1.79*10^308~+1.79*10^308
//3. 优先级从高到低顺序为!>&&>||
return 0;
}