洛谷题单代码【入门1 顺序结构】

洛谷题单代码【入门1 顺序结构】

  • A+B Problem
  • 超级玛丽游戏
  • 苹果采购
  • 字母转换
  • 数字反转
  • 再分肥宅水
  • 小鱼的游泳时间
  • 小学数学N合一
  • 三角形面积
  • 10.小玉买文具
  • Apples Prologue
  • 对角线
  • 上学迟到
  • 成绩
#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(){
    cout <<
    "                ********\n"
    "               ************\n"
    "               ####....#.\n"
    "             #..###.....##....\n"
    "             ###.......######              ###            ###\n"
    "                ...........               #...#          #...#\n"
    "               ##*#######                 #.#.#          #.#.#\n"
    "            ####*******######             #.#.#          #.#.#\n"
    "           ...#***.****.*###....          #...#          #...#\n"
    "           ....**********##.....           ###            ###\n"
    "           ....****    *****....\n"
    "             ####        ####\n"
    "           ######        ######\n"
    "##############################################################\n"
    "#...#......#.##...#......#.##...#......#.##------------------#\n"
    "###########################################------------------#\n"
    "#..#....#....##..#....#....##..#....#....#####################\n"
    "##########################################    #----------#\n"
    "#.....#......##.....#......##.....#......#    #----------#\n"
    "##########################################    #----------#\n"
    "#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#\n"
    "##########################################    ############"
    << endl;


    return 0;
}

#include <iostream>
using namespace std;

/*
现在需要采购一些苹果,
每名同学都可以分到固定数量的苹果,
并且已经知道了同学的数量,请问需要采购多少个苹果?
*/
int main(){
    int num, student;
    cin >> num >> student;
    cout << num * student << endl;

    return 0;
}

#include <iostream>
using namespace std;

int main(){
    char ch;
    cin >> ch;
    cout << char(ch - 32) << endl;

    return 0;
}

#include<iostream>
using namespace std;

float reverseNum(float f);
int main(){
	float f;
	cin >> f;
	
	cout << reverseNum(f) << endl;
}
float reverseNum(float f){
	int temp = f * 10;
	int t = temp % 10, num = 0;
	while(temp > 0){
		num = num * 10 + temp % 10;
		temp /= 10;
	}
	return num * 0.001;
}

#include <iostream>
#include <iomanip> //使用 setprecision(n)设置精度需要的库函数 
using namespace std;

int main(){
	double t;
	int n;
	cin >> t >> n;
	//setprecision(n),表示数值的有效位为n 
	//加了fixed 是固定点方式显示, 表示为小数点后n位 
	cout << fixed << setprecision(3) << t / n << endl;
	cout << 2 * n << endl; 
	
	return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int getHour(int startHour, int endHour){
	int hour = 0;
	if(startHour > endHour){
			hour = 24 - startHour + endHour;
		} else{
			hour = endHour - startHour;
		}
	return hour;
}
int main(){
	int startHour, startMin, endHour, endMin;
	int min = 0, hour = 0;
	cin >> startHour >> startMin >> endHour >> endMin;
	if(startMin > endMin){
		endHour = endHour == 0 ? 23 : endHour - 1;
		min = 60 - startMin + endMin;
		hour = getHour(startHour, endHour);
	} else {
		min = endMin - startMin;
		hour = getHour(startHour, endHour);
	}
	
	cout << hour << " " << min << endl;
	
	return 0;
} 

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;

int num = 1; //吃桃子的次数 
int question9(int n){
	if(num == 4){
		return n; 
	}
	++num;
	return question9((n + 1) * 2);
}
int main(){
	int t;
	cin >> t;
	int result = 0, sum = 0, n = 0, num = 0, total = 0;
	char ch = ' ';
	double pi = 3.141593, v = 0.0;
	float free = 0.0, temp = 0.0;
	
	switch(t){
		case 1:
			cout << "I love Luogu!" << endl;
			break;
		case 2:
			cout << 2 + 4 << " " << 10 - 2 - 4 << endl;
			break;
		case 3:
			cout << 14 / 4 << endl;
			cout << 14 - 14 % 4 << endl;
			cout << 14 % 4 << endl;
			break;
		case 4:
			cout << setprecision(6) << 500.0 / 3 << endl;
			break;
		case 5:
			//相遇问题:路程和=时间*速度和 
			cout << (220 + 260) / (20 + 12) << endl;
			break;
		case 6:
			cout << sqrt(6 * 6 + 9 * 9) << endl;
			break;
		case 7:
			sum = 100;
			cout << sum + 10 << endl;
			cout << sum + 10 - 20 << endl;
			cout << sum - sum << endl;
			break;
		case 8:
			cout << 2 * 5 * pi << endl;
			cout << pi * 5 * 5 << endl;
			cout << 1.0 * 4 / 3 * pi * 5 * 5 * 5 << endl;
			break;
		case 9:
			cout << question9(1) << endl;
			break;
		case 10:
			cout << 9 << endl;
			break;
		case 11:
			//路程差 / 速度差 = 追及时间 
			cout << 100.0 / 3.0 << endl;
			break;
		case 12:
			n = 1;
			ch = 'A';
			while(++n < 19){
				ch += 1;
				if(ch == 'M'){
					cout << n << endl;
				}
				
			}
			cout << ch << endl;
			break;
		case 13:
			v = pi * 4 * 4 * 4 * 4 / 3 + pi * 10 * 10 * 10 * 4 / 3;
			cout << int(pow(v, 1.0/3)) << endl;
			break;
		case 14:
			num = 10, total = 0;
			free = 110, temp = free * num;	
			while(temp < 3500){
				free -= 1;
				num += 1;
				temp = free * num;
			}
			//free = int(floor(free + 0.5)); //实现四舍五入
			cout << num << endl; 
	} 
	
	return 0;
}

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	double a, b, c;
	double p = 0.0;
	cin >> a >> b >> c;
	p = 0.5 * (a + b + c);
	cout << fixed << setprecision(1)
	<< sqrt(p * (p - a) * (p - b) * (p - c)) << endl;
	
	return 0;
} 

#include <iostream>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	cout << int((a + b * 0.1) / 1.9) << endl;
	
	return 0;
}

#include <iostream>
using namespace std;

int main(){
	int m, t, s;
	cin >> m >> t >> s;
	//吃掉n个苹果 t为0则直接吃掉所有苹果 
	int n = t != 0 ? (s % t == 0 ? s / t : s / t + 1) : m; 
	int apples = m >= n ? m - n : 0;
	cout << apples << endl;
	
	return 0;
}

#include <iostream>
using namespace std;
typedef unsigned long long ull;

ull point[100005] = {0};
ull sum[100005] = {0};
int main(){
	//递推
	int n;
	cin >> n;
	point[4] = 1;
	for(ull i = 1; i <= n; i++){//预处理n^2的前缀和 
		sum[i] = sum[i - 1] + i * i;
	}
	for(ull i = 5; i <= n; i++){
		point[i] = point[i - 1] + (i - 2) * (i - 2) * (i - 3) / 2 - sum[i - 3];
	}
	cout << point[n] << endl;
	return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int main(){
	const int total = 8 * 60;
	int before = 0, hours = 0, minutes = 0;
	int s, v;
	scanf("%d %d", &s, &v);
	int time = ceil(1.0 * s / v) + 10;
	if(time > total){//如果超过八小时,在前一天 
		minutes = time - total;
		hours = 0;
		while(minutes >= 60){
			++hours;
			minutes -= 60;
		} 
		hours = hours == 0 ? hours : 23 - hours;
		minutes = 60 - minutes;
	} else {
		hours = 7;
		minutes = time;
		while(minutes >= 60){
			--hours;
			minutes -= 60;
		}
		minutes = 60 - minutes;
	}
	printf("%s%d:%s%d\n", hours < 10 ? "0" : "", hours, minutes < 10 ? "0" : "" , minutes);
	
	return 0;
}

#include <iostream>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * 0.2 + b * 0.3 + c * 0.5 << endl; 
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值