当前位置: 首页 > news >正文

C++ 变量、输入输出、表达式和顺序语句 ac-wing

输入两个整数,求这两个整数的和是多少。

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

#include<iostream>
using namespace std;
int main()
{int A,B,C,D;cin>>A>>B>>C>>D;cout<<"DIFERENCA = "<< A * B - C * D;return 0;
}

圆的面积

#include <iostream>
#include <cstdio> // 运用scanf/printf函数
#define PI 3.14159using namespace std;int main()
{double R, A;scanf("%lf", &R);A = R * R * PI;printf("A=%.4lf", A);return 0;
}

平均数1

在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{double a,b;cin>>a>>b;printf("MEDIA = %.5lf",(a*3.5+b*7.5)/11);//11=3.5+7.5return 0;
}

工资

在这里插入图片描述

#include <cstdio> 
using namespace std;
int main()
{int number,hour;double money;scanf("%d%d%lf " , &number, &hour, &money);printf("NUMBER = %d\n ", number);printf("SALARY = U$ %.2lf\n ", hour * money);return 0;
}

油耗

#include<iostream>
using namespace std;
int main()
{int X;double Y;cin>>X>>Y;printf("%.3lf km/l",X/Y);return 0;
}

两点间的距离

在这里插入图片描述

#include <iostream>
#include <cmath>
using namespace std;
int main()
{double x1, y1, x2, y2;cin >> x1 >> y1 >> x2 >> y2;printf("%.4lf", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));return 0;
}

钞票

在这里插入图片描述

#include <iostream>
using namespace std;
int main()
{int n, a[7] = {100, 50, 20, 10, 5, 2, 1};cin >> n;printf("%d\n", n);for (int i = 0; i < 7; i ++ ){printf("%d nota(s) de R$ %.2lf\n", n / a[i], a[i]);n %= a[i];}return 0;
}

时间转化

#include <iostream>using namespace std;int main()
{int t;cin >> t;int h = t / 3600;int m = t % 3600 / 60;int s = t % 60;cout << h << ':' << m << ':' << s << endl;return 0;
}

简单计算

在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{int code,n;double price,sum=0.0;for(int i=1;i<=2;i++)cin>>code>>n>>price,sum+=n*price;printf("VALOR A PAGAR: R$ %.2lf",sum);return 0;
}

燃料消耗

在这里插入图片描述

  • 这个题数据范围挺大,小心溢出
#include<iostream>
using namespace std;
int a, b;
int main() {scanf("%d%d", &a, &b);printf("%.3lf", a * 1.000 / 12 * b); //先除再乘,以免double溢出return 0;
}

钞票和硬币

在这里插入图片描述

  • 数值放大 解法和上面类似
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{double n;cin >> n;int m = (int)(n * 100);double a[12] = {10000, 5000, 2000, 1000, 500, 200, 100, 50, 25, 10, 5, 1};int ans[12] = {0};for (int i = 0; i < 12; i++){int cnt = 0;while (m >= a[i]){m -= a[i];cnt++;}ans[i] = cnt;}puts("NOTAS:");for (int i = 0; i < 6; i++)printf("%d nota(s) de R$ %.2lf\n", ans[i], (double)a[i] / 100);puts("MOEDAS:");for (int i = 6; i < 12; i++)printf("%d moeda(s) de R$ %.2lf\n", ans[i], (double)a[i] / 100);return 0;
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • css加载一张图片 设置整个页面背景
  • 前端面试宝典【CSS篇】【8】
  • 使用WSL在Windows上安装Linux
  • LuaJit分析(六)luajit -bl 命令分析
  • Java 入门指南:Java 并发编程 —— JMM Java内存模型
  • sql-labs靶场(41-50)
  • Linux主机网络参数的设置—IP地址的作用和类型
  • 十一头像红旗怎么弄的?3个方法轻松教会你!
  • 贴梗海棠T2T基因组-文献精读40
  • 网优学习干货:2.6G仿真操作(2)
  • PTA - C语言接口题集2
  • 算法练习题06:leetcode793每日温度
  • 04:布局规划
  • 一个php快速项目搭建框架源码,带一键CURD等功能
  • DRF——serializer中获取嵌套评论
  • Google 是如何开发 Web 框架的
  • ES6, React, Redux, Webpack写的一个爬 GitHub 的网页
  • gitlab-ci配置详解(一)
  • Go 语言编译器的 //go: 详解
  • Hibernate【inverse和cascade属性】知识要点
  • Iterator 和 for...of 循环
  • Laravel 菜鸟晋级之路
  • 阿里云购买磁盘后挂载
  • 动态魔术使用DBMS_SQL
  • 基于axios的vue插件,让http请求更简单
  • 聊聊flink的BlobWriter
  •  一套莫尔斯电报听写、翻译系统
  • 用jquery写贪吃蛇
  • 优秀架构师必须掌握的架构思维
  • 原生 js 实现移动端 Touch 滑动反弹
  • Hibernate主键生成策略及选择
  • #14vue3生成表单并跳转到外部地址的方式
  • #define与typedef区别
  • #周末课堂# 【Linux + JVM + Mysql高级性能优化班】(火热报名中~~~)
  • ()、[]、{}、(())、[[]]等各种括号的使用
  • (+4)2.2UML建模图
  • (附源码)php投票系统 毕业设计 121500
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (五)activiti-modeler 编辑器初步优化
  • (一)C语言之入门:使用Visual Studio Community 2022运行hello world
  • (一)使用IDEA创建Maven项目和Maven使用入门(配图详解)
  • (原创) cocos2dx使用Curl连接网络(客户端)
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (转)拼包函数及网络封包的异常处理(含代码)
  • (最完美)小米手机6X的Usb调试模式在哪里打开的流程
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • .Net MVC + EF搭建学生管理系统
  • .NET 的静态构造函数是否线程安全?答案是肯定的!
  • .NET 中 GetProcess 相关方法的性能
  • .Net多线程总结
  • /etc/sudoer文件配置简析
  • :“Failed to access IIS metabase”解决方法
  • @require_PUTNameError: name ‘require_PUT‘ is not defined 解决方法
  • @Transactional事务注解内含乾坤?
  • [ Linux ] git工具的基本使用(仓库的构建,提交)