zoukankan      html  css  js  c++  java
  • 【NOI OpenJudge】【1.3】编程基础之算术表达式与顺序执行

    在这里插入图片描述

    01: A+B问题

    #include<iostream>
    using namespace std;
    int main(){
    	int a, b;
    	cin>>a>>b;
    	cout<<a+b<<"
    ";
    	return 0;
    }
    

    02: 计算(a+b)*c的值

    #include<iostream>
    using namespace std;
    int main(){
    	int a, b, c;
    	cin>>a>>b>>c;
    	cout<<(a+b)*c<<"
    ";
    	return 0;
    }
    

    03:计算(a+b)/c的值

    #include<iostream>
    using namespace std;
    int main(){
    	int a, b, c;
    	cin>>a>>b>>c;
    	cout<<(a+b)/c<<"
    ";
    	return 0;
    }
    

    04: 带余除法

    #include<iostream>
    using namespace std;
    int main(){
    	int a, b;
    	cin>>a>>b;
    	cout<<a/b<<' '<<a%b<<'
    ';
    	return 0;
    }
    
    

    05:计算分数的浮点数值

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	double a, b;
    	scanf("%lf%lf",&a,&b);
    	double c = a/b;
    	printf("%.9lf",c);
    	return 0;
    }
    
    

    06:甲流疫情死亡率

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	//int a, b;
    	double a, b;
    	scanf("%lf%lf",&a,&b);
    	double c = b/a*100;
    	printf("%.3lf%%",c);
    	return 0;
    }
    
    

    07: 计算多项式的值

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	double x, a, b, c, d;
    	scanf("%lf%lf%lf%lf%lf",&x,&a,&b,&c,&d);
    	double ans = x*x*x*a+b*x*x+c*x+d;
    	printf("%.7lf",ans);
    	return 0;
    }
    
    

    08:温度表达转化

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	double x;
    	scanf("%lf",&x);
    	double ans = 5*(x-32)/9;
    	printf("%.5lf",ans);
    	return 0;
    }
    
    

    09:与圆相关的计算

    #include<cstdio>
    #include<iostream>
    using namespace std;
    const double pi=3.14159;
    int main(){
    	double x;
    	scanf("%lf",&x);
    	printf("%.4lf %.4lf %.4lf",x*2,2*pi*x,pi*x*x);
    	return 0;
    }
    
    

    10:计算并联电阻的阻值

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	float a, b;
    	scanf("%f%f",&a,&b);
    	float r = 1/(1/a + 1/b);
    	printf("%.2f",r);
    	return 0;
    }
    
    

    11:计算浮点数相除的余数

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	double a, b;
    	scanf("%lf%lf",&a,&b);
    	int k = 0;
    	while(a-k*b >= 0){
    		k++;
    	}
    	k--;
    	printf("%g",a-k*b);
    	return 0;
    }
    

    12: 计算球的体积

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	double x;
    	double pi = 3.14;
    	scanf("%lf",&x);
    	printf("%.2lf",4.0*pi*x*x*x/3);
    	return 0;
    }
    
    

    13:反向输出一个三位数

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int cur;
    void go(){
    	char ch;
    	if(++cur <= 3){
    		ch = getchar();
    		go();
    		putchar(ch);
    	}
    }
    int main(){
    	go();
    	return 0;
    }
    
    

    14:大象喝水

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	double h, r;
    	double pi = 3.14;
    	scanf("%lf%lf",&h,&r);
    	r*=0.01, h *= 0.01;
    	double v = pi*r*r*h;
    	double ans = 20/(v*1000);
    	printf("%d",(int)(ans-0.0001)/1+1);
    	return 0;
    }
    
    

    15:苹果和虫子

    #include<cstdio>
    #include<iostream>
    using namespace std;
    int main(){
    	int n, x, y;
    	cin>>n>>x>>y;
    	int b = (int)((y*1.0/x*1.0-0.001)+1);
    	cout<<n-b<<'
    ';
    	return 0;
    }
    
    

    16:计算线段长度

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
    	double x1, y1, x2, y2;
    	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    	printf("%.3lf
    ",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    	return 0;
    }
    
    

    17:计算三角形面积

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
    	double x1, y1, x2, y2, x3, y3;
    	scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    	double a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    	double b = sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
    	double c = sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    	double p = (a+b+c)/2;
    	printf("%.2lf
    ",sqrt(p*(p-a)*(p-b)*(p-c)));
    	return 0;
    }
    

    18:等差数列末项计算

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
    	int a1, a2;
    	cin>>a1>>a2;
    	int d = a2-a1;
    	int n;  cin>>n;
    	cout<<a1+(n-1)*d<<'
    ';
    	return 0;
    }
    
    

    19:A*B问题

    #include<iostream>
    using namespace std;
    int main(){
    	long long a, b;
    	cin>>a>>b;
    	cout<<a*b<<'
    ';
    	return 0;
    }
    
    
    

    20:计算2的幂

    #include<iostream>
    using namespace std;
    int main(){
    	int n;  cin>>n;
    	cout<<(1<<n);
    	return 0;
    }
    
    
  • 相关阅读:
    Python IDLE快捷键一览
    面试题——中
    面试题——君
    面试题——太(下)
    面试题——2面常见问题
    MYSQL数据库设计规范与原则
    字符串操作
    集合
    java-数组
    java异常处理机制
  • 原文地址:https://www.cnblogs.com/gwj1314/p/10200060.html
Copyright © 2011-2022 走看看