当前位置:网站首页>洛谷入门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;
}
边栏推荐
- CAS comparison and exchange
- About sitemap XML problems
- SQL parsing practice of Pisa proxy
- Fundamentals of software engineering (I)
- 隱私計算FATE-離線預測
- At a time of oversupply of chips, China, the largest importer, continued to reduce imports, and the United States panicked
- 16 -- 删除无效的括号
- CNN convolutional neural network (the easiest to understand version in History)
- Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
- E ModuleNotFoundError: No module named ‘psycopg2‘(已解决)
猜你喜欢

Computer screen splitting method

Use GCC to generate an abstract syntax tree "ast" and dump it to Dot file and visualization

巧用redis实现点赞功能,它不比mysql香吗?

HTTP Caching Protocol practice

sql注入原理

Knowledge map model

ReentrantLock、ReentrantReadWriteLock、StampedLock

Volatile and JMM

CentOS8-postgresql初始化时报错:initdb: error: invalid locale settings; check LANG and LC_* environment
![[xman2018 qualifying] pass](/img/eb/7bf04941a96e9522e2b93859266cf2.png)
[xman2018 qualifying] pass
随机推荐
Admixture usage document Cookbook
Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
Different perspectives
[digital signal processing] discrete time signal (analog signal, discrete time signal, digital signal | sampling leads to time discrete | quantization leads to amplitude discrete)
Professor huangxutao, a great master in CV field, was born at the age of 86. UIUC specially set up a doctoral scholarship to encourage cutting-edge students
Leetcode 724. 寻找数组的中心下标(可以,一次过)
Go error collection | when a function uses a return value with a parameter name
Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and the mobile phone can easily read literature
PCL Library - error reporting solution: cmake and Anaconda conflicts during installation
Knowledge map model
Reflection learning summary
Google tool splits by specified length
Leetcode 724. Find the central subscript of the array (yes, once)
On traversal of tree nodes
【170】PostgreSQL 10字段类型从字符串修改成整型,报错column cannot be cast automatically to type integer
Can the teacher tell me what the fixed income + products are mainly invested in?
固收+产品有什么特点?
R language error
2022-2-16 learning the imitated Niuke project - Section 6 adding comments
[microservices sentinel] hotspot rules | authorization rules | cluster flow control | machine list