Acwing语法基础课题目练习

变量、输入输出、表达式与顺序语句

616. 两点间的距离

#include 
#include 
#include 
#include 
using namespace std;
int main()
{
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    double s;
    s=sqrt((c-a)*(c-a)+(d-b)*(d-b));
    printf("%.4f",s);
    return 0;
}

653. 钞票

#include 
#include 
#include 
#include 
using namespace std;
int main()
{
    int N;
    cin >> N;
    cout<<N<<"\n";
    printf("%d nota(s) de R$ 100,00\n", N/100);
    N = N % 100;
    printf("%d nota(s) de R$ 50,00\n", N / 50);
    N = N % 50;
    printf("%d nota(s) de R$ 20,00\n", N / 20);
    N=N%20;
    printf("%d nota(s) de R$ 10,00\n", N / 10);
    N=N%10;
    printf("%d nota(s) de R$ 5,00\n", N / 5);
    N=N%5;
    printf("%d nota(s) de R$ 2,00\n", N / 2);
    N=N%2;
    printf("%d nota(s) de R$ 1,00\n", N / 1);
    N=N%1;
}

654. 时间转换

#include 
#include 
#include 
using namespace std;

int main()
{
    int n;
    cin >> n;
    printf("%d:%d:%d",n/3600,n/60%60,n%60);
    return 0;
}

605. 简单乘积

#include 
#include 
#include 
using namespace std;

int main()
{
    int n,m,s;
    cin >> n>>m;
    cout<<"PROD = "<<m*n;
    return 0;
}

AcWing 611. 简单计算

#include 
#include 
#include 
using namespace std;

int main()
{
    int a, b;
    double d, c;
    cin >> a >> a >> c;
    cin >> b >> b >> d;
    printf("VALOR A PAGAR: R$ %.2f",a*c+b*d);
    return 0;
}

657. 选择练习1

#include 
#include 
#include 
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((b>c)&&(d>a)&&((c+d)>(a+b))&&(c>0)&&(d>0)&&(a%2==0))
        cout<<"Valores aceitos";
    else
        cout<<"Valores nao aceitos";
}

AcWing 662. 点的坐标

#include 
#include 
#include 
using namespace std;
int main()
{
    double a,b;
    cin>>a>>b;
    if((a>0)&&(b>0))
        cout<<"Q1"<<endl;
    else if((a<0)&&(b>0))
        cout<<"Q2";
    else if((a<0)&&(b<0))
        cout<<"Q3";
    else if((a>0)&&(b<0))
        cout<<"Q4";
    else if((a==0)&&(b==0))
        cout<<"Origem";
    else if(b==0)
        cout<<"Eixo X";
    else if(a==0)
        cout<<"Eixo Y";
    return 0;
}

717. 简单斐波那契

#include 
#include 
#include 

using namespace std;
int a[50];
int main()
{
    int n;
    cin>>n;
    if(n == 1)
    {
        cout << 0;
        return 0;
    }
    a[0]=0,a[1]=1;
    cout<<0<<" "<<1<<" ";
    for (int i = 2; i < n; i ++ )
    {
        a[i]=a[i-1]+a[i-2];
        cout<<a[i]<<" ";
    }
    return 0;
}
#include 
#include 
#include 

using namespace std;


int main()
{
    int n;
    cin>>n;

    int a, b, c;
    a = 0;
    b = 1;
    c = 1;
    for (int i = 0; i < n; i ++ )
    {
        cout << a << " ";
        c = b + c;
        int t = b;
        b = a + b;
        a = t;
    }

    return 0;
}

AcWing 726. 质数

#include 
#include 
#include 
#include 
using namespace std;

int check(int n)
{
    if(n<=1)
        return 0;
    else 
    {
        for(int i=2;i<=sqrt(n);i++)
        {
            if( n%i == 0)
                return 0;
        }
        return 1;
    }
}

int main()
{
    int T;
    cin >> T;
    while(T -- )
    {
        int n;
        cin >> n;
        if(check(n) == 0)
            cout << n << " is not prime\n";
        else 
            cout << n << " is prime\n";
    }
    return 0;
}
#include 
#include 
#include 
#include 
using namespace std;

int main()
{
    int n;
    cin>>n;
    for (int i = 0; i < n; i ++ )
    {
        int x;
        cin>>x;
        int len = 0;
        
        for(int j=2;j<=sqrt(x);j++)
        {
            if(x%j==0)
            {
                cout<<x<<" is not prime \n";
                len = 1;
                break;
            }
        }
        if (len == 0)
            cout<<x<<" is prime\n";
    }
    
    return 0;
}

你可能感兴趣的:(复试,算法,c++,数据结构)