来自noj的期末复习

来自noj的期末复习

1.找幸运数
在这里插入图片描述

#include 
using namespace std;
int main(){
    int N,n,num=0;
    cin>>N;
    n=N;
    while(N!=0){
        num=num*10;
        num+=N%10;
        N/=10;
    }
    n==num?cout<<"yes"<<'\n':cout<<"no"<<endl;
   
    return 0;
}

2.奖金发放
来自noj的期末复习_第1张图片

#include 
#include
#include 
using namespace std;
int main(){
    double i,a=0;
    cin>>i;
    if (i<=10){
        a=i*(0.1);
    }else if(i<=20){
        a=10*0.1+(i-10)*0.075;
    }else if(i<=40){
        a=10*0.1+10*0.075+(i-20)*0.05;
    }else if(i<=60){
        a=10*0.1+10*0.075+20*0.05+(i-40)*0.03;
    }else if(i<=100){
        a=10*0.1+10*0.075+20*0.05+20*0.03+(i-60)*0.015;
    }else {a=10*0.1+10*0.075+20*0.05+20*0.03
        +40*0.015+(i-100)*0.01;}
    
    cout<<fixed<<setprecision(6)<<a<<endl;
    return 0;
}

3.出租车费

来自noj的期末复习_第2张图片

#include 
#include
#include 
#include
using namespace std;
int main(){
    double a,b,m;
    cin>>a;
    if(a<=2){
        b=7;
    }else if (a<=15){
        m=ceil(a);//主要是学习ceil函数的应用
        b=7+(m-2)*1.5;
    }else {
        m=ceil(a);
        b=7+13*1.5+(m-15)*2.1;
    }
    cout<<fixed<<setprecision(6)<<b<<endl;
    return 0;
}

4.是该年的第几天
来自noj的期末复习_第3张图片

#include 
#include 
#include 
using namespace std;
int get_days(int year,int month){
    switch(month){
        case 1:case 3:case 5:case 7:
        case 8:case 10:case 12:
            return 31;
        case 4:case 6:case 9:case 11:
            return 30;
        case 2:
            if((year%4==0&&year%100!= 0)||year%400==0)
                return 29;//闰年的概念
            else return 28;
    }
    return 0;
}
int main(){
    int year ,month,day;
    scanf("%d-%d-%d",&year,&month,&day);
    //记住scanf的用法
    if (month <0||month>12)
        return 1;
    int days=day;
    for (int i=1;i<month;i++){
        int dm=get_days(year ,i);
        days+=dm;
    }
    cout<<days<<endl;
    return 0;
}

5.求建筑高度
来自noj的期末复习_第4张图片

#include 
#include 
#include
using namespace std;
int main(){
    float x,y;
    int h;
    scanf("%f,%f",&x,&y);
    if((x-2)*(x-2)+(y-2)*(y-2)<=1||
       (x-2)*(x-2)+(y+2)*(y+2)<=1||
       (x+2)*(x+2)+(y-2)*(y-2)<=1||
       (x+2)*(x+2)+(y+2)*(y+2)<=1){
        h=10;
    }else {h=0;}
    cout<<h<<endl;
        
       return 0;
}

6.区间内素数
来自noj的期末复习_第5张图片

#include 
#include 
#include
#include
using namespace std;
int main(){
    int a=799,b,c,cnt=0,sum=0,d=1;
    while(a>500&&a<800){
        c=0;
        b=a-1;
        while(b>1){
            if(a%b==0)
                c=c+1;
            b=b-1;
        };
        if(c==0){
            cnt+=1;
            sum+=d*a;
            d=-1*d;
        };
        a=a-1;
    }
    cout<<cnt<<" "<<sum<<endl;
    return 0;
}

7.你会存钱吗?

来自noj的期末复习_第6张图片

#include 
#include 
#include
#include
using namespace std;
int main(){
    int i8,i5,i3,i2,i1,n8,n5,n3,n2,n1;
    float max=0,term;
    for(i8=0;i8<3;i8++)
        for(i5=0;i5<=(20-8*i8)/5;i5++)
            for(i3=0;i3<=(20-i8*8-i5*5)/3;i3++)
                for(i2=0;i2<=(20-i8*8-i5*5-i3*3)/2;i2++){
                    i1=20-i8*8-i5*5-i3*3-i2*2;
                    term=2000.0*pow((double)(1+0.0063*12),(double)i1)
                    *pow((double)(1+0.0066*12),(double)i2)
                    *pow((double)(1+3*0.0069*12),(double)i3)
                    *pow((double)(1+5*0.0075*12),(double)i5)
                    *pow((double)(1+8*0.0084*12),(double)i8);
                    if(term>max){
                        max=term;
                        n1=i1;
                        n2=i2;
                        n3=i3;
                        n5=i5;
                        n8=i8;
                    }
                }
    cout<<n8<<" "<<n5<<" "<<n3<<" "<<n2<<" "<<n1<<endl;
    cout<<max<<endl;
    return 0;
}
//确实有点麻烦

还有好多题,我发现我好多不会。。。。

你可能感兴趣的:(来自noj的期末复习)