当前位置:网站首页>洛谷入门1【顺序结构】题单题解
洛谷入门1【顺序结构】题单题解
2022-06-27 15:23:00 【阳懿】
目录
【入门1】顺序结构 - 题单 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
超级玛丽
- C++多行输出用 R"( )"
#include<iostream>
using namespace std;
int main() {
cout<<R"( ********
************
####....#.
#..###.....##....
###.......###### ### ###
........... #...# #...#
##*####### #.#.# #.#.#
####*******###### #.#.# #.#.#
...#***.****.*###.... #...# #...#
....**********##..... ### ###
....**** *****....
#### ####
###### ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
########################################## #----------#
#.....#......##.....#......##.....#......# #----------#
########################################## #----------#
#.#..#....#..##.#..#....#..##.#..#....#..# #----------#
########################################## ############)"<<endl;
return 0;
}字母转换
- 题目:输入一个小写字母,输出其对应的大写字母。例如输入 q[回车] 时,会输出 Q。
- 注意 :toupper 返回的是int值,若要返回一个字母,还要加上char,即char(toupper())
#include<iostream> #include<ctype.h> using namespace std; int main(){ char a; cin>>a; cout<<char(toupper(a)); return 0; }
数字反转
- 利用scanf和printf
#include<iostream>
using namespace std;
int main(){
char a,b,c,d;
scanf("%c%c%c.%c",&a,&b,&c,&d);
printf("%c.%c%c%c",d,c,b,a);
return 0;
}再分肥皂水
- 输入保留三位小数 %.3f
printf("%.3f\n",t/n);小鱼的游泳时间
#include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
//在同一天,c一定大于a,只需要判断d和b
if(d>=b)
{
cout<<c-a<<" "<<d-b;
}
else
{
cout<<c-a-1<<" "<<d+60-b;
}
return 0;
}小学数学N合1
- 注意1.0/4 和 1/4 的区别
- 如果是1/4 得出结果为0, 1/3同理 但是1.0/4 会得出0.25

1/4 int类型, 1.0/4 double类型; 1/4.0 double类型 也得出0.25
表达式的结果为最高类型的结果
else if(T==13)
{cout<<(int)(pow(1.0*4/3*pi*1064,1.0/3))<<endl;}三角形面积
- sqrt平方根函数

苹果和虫子
- 剩下几个完整的苹果,那么吃了几口的苹果肯定不算,最后结果转为int 直接抹去小数点后

#include<iostream>
using namespace std;
int main(){
double m,t,s;
cin>>m>>t>>s;
if(t==0) //注意当吃一个苹果需要0分钟时,意思是吃苹果很快,最后肯定剩下0个苹果。
{cout<<"0"<<endl;}
else if((int)(m-s/t)<=0){
cout<<"0"<<endl;}
else{
cout<<(int)(m-s/t)<<endl;}
return 0;
}对角线
- 四个顶点有一个对角线交点
- unsigned long long范围比long long范围大
- unsigned long long 的范围是[0,2^64-1]。long long 的范围是[-2^63-1,2^63+1]
n和n-1一定有一个是2的倍数,因此2可以除尽;同理n,n-1,n-2中一定有一个是3的倍数,因此3可以除尽(除掉2只会消除因数2而对3没有影响);同理4也可以除尽
#include<iostream>
using namespace std;
int main(){
unsigned long long n;
cin>>n;
cout<<n * (n-1) / 2 * (n-2) / 3 * (n-3) / 4<<endl;
return 0;
}
上学迟到
- ceil()向上取整
#include<iostream>
#include<math.h>
using namespace std;
int main() {
double s, v;
int hour = 7, min;
cin >> s >> v;
int total = ceil(s / v) + 10; //ceil() 向上取整 3/2=2 ceil(s/v) eg:花费3.2分钟,按照4分钟计算
int totalhour = total / 60;
min = 60 - total % 60; //70min, 6:50 60-10
if (total % 60 == 0)
min = 00;
while (totalhour--)
{
hour--; //如果只写if (hour < 0) 当hour = 24;时 结果中有24:30 hour从7开始设置,前一天同理,
if (hour < 0 && min != 00)
hour = 23;
else if (hour < 0)
hour = 24;
}
printf("%02d:%02d",hour ,min );
return 0;
}
边栏推荐
- Creation and use of static library (win10+vs2022
- Abnormal analysis of pcf8591 voltage measurement data
- AI begets the moon, and thousands of miles share the literary heart
- 522. 最长特殊序列 II / 剑指 Offer II 101. 分割等和子集
- 2022-2-15 learning the imitated Niuke project - Section 5 shows comments
- Notes learning summary
- AQS抽象队列同步器
- 522. longest special sequence II / Sword finger offer II 101 Split equal sum subset
- Brief reading of dynamic networks and conditional computing papers and code collection
- 基于WEB平台的阅读APP设计与实现
猜你喜欢

E ModuleNotFoundError: No module named ‘psycopg2‘(已解决)

What is the London Silver code

R language objects are stored in JSON

CAS comparison and exchange

Design and implementation of food recipe and ingredients website based on vue+node+mysql

Fundamentals of software engineering (I)

Why can't the start method be called repeatedly? But the run method can?
![[an Xun cup 2019]attack](/img/1a/3e82a54cfcb90ebafebeaa8ee1ec01.png)
[an Xun cup 2019]attack

AutoCAD - line width setting

PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)
随机推荐
Atomic operation class
海量数据!秒级分析!Flink+Doris构建实时数仓方案
All you want to know about large screen visualization is here
易周金融 | Q1手机银行活跃用户规模6.5亿;理财子公司布局新兴领域
How to change a matrix into a triple in R language (i.e. three columns: row, col, value)
[microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list
On traversal of tree nodes
Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
AQS抽象队列同步器
CNN convolutional neural network (the easiest to understand version in History)
In the past, domestic mobile phones were arrogant in pricing and threatened that consumers would like to buy or not, but now they have plummeted by 2000 for sale
CV领域一代宗师黄煦涛教授86岁冥诞,UIUC专设博士奖学金激励新锐
注解学习总结
How QT sets some areas to be transparent in the background image
基于SSM的Web网页聊天室系统
Pisa-Proxy 之 SQL 解析实践
Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme
SQL parsing practice of Pisa proxy
2022-2-15 learning the imitated Niuke project - Section 5 shows comments
PR second training notes