ACM杂记

来源:互联网 发布:seo查询爱站网 编辑:程序博客网 时间:2024/05/16 10:33

1.如何使用sin,cos。
首先引入数学库函数,include < cmath>,然后因为sin要求输入的是弧度,所以要转化一下 。 就是 弧度 = 角度 * PI /180 ;

#include<iostream>#include<cstdio>#include<cmath>using namespace std ; const double pi = acos(-1.0); // 注意用这个来精确的求PI的值int main(){    freopen("debug//in.txt","r",stdin);    freopen("debug//out.txt","w",stdout);    int n   ;    scanf("%d",&n);    printf("%f",sin(n*pi/180.0));    fclose(stdin);    fclose(stdout);    return 0 ; }

2.数组的升序和降序
引入algorithm 算法的库函数。

sort(a, a+10 ,less<int>()); // 升序
sort(a, a+10 ,greater<int>() ) ; //降序

include<cstdio>include<algorithm>int main(){    int a[10] = {22 ,11 ,44 ,34,545 ,45 ,433 ,0 ,1 ,3};    sort(a,a+10,less<int>());  //升序排列    for(int i = 0 ; i < 10 ; i++)        printf("%d\n",a[i]);    sort(a,a+10 , greater<int>()) ; //降序排列    for(int i = 0 ; i < 10 ; i++)        printf("%d\n",a[i]);    return 0 ; }
0 0
原创粉丝点击