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

LeetCode刷题计划

LeetCode刷题计划

推荐 代码随想录:https://github.com/youngyangyang04/leetcode-master


卡码网 练习ACM模式 https://kamacoder.com/

01

在这里插入图片描述

#include <iostream>
using namespace std;int main()
{int a ,b;while(cin>>a>>b){cout<<a+b<<endl;}return 0;
}
while True:try:a,b = map(int,input().split())print(a+b)except EOFError:break

注意:

  • try和except配套用
  • python输入是使用a = int(input())
  • 输入一行,使用map(int,input().split())
  • 遇到说潜在的指针越界就是没有break

02

#include <bits/stdc++.h>
using namespace std;int main()
{int a, b, n;while(cin>>n){for (int i = 0; i < n; ++i) {cin >> a >> b;cout << a + b << endl;}}return 0;
}#include <iostream>
using namespace std;int main(){int n;int a,b;while(cin>>n){ while(n>0){cin>>a>>b;cout<<a+b<<endl;n--;}
}return 0;}
try:while True:n = int(input())  # 输入行数for _ in range(n):a, b = map(int, input().split())print(a + b)
except EOFError:pass  # 捕获EOFError异常,结束循环

注意:

  • #include <bits/stdc++.h>是万能头文件
  • python的单个循环可使用for _ in range(n):

03

在这里插入图片描述

#include <bits/stdc++.h>int main(){int a ,b ;while(true){std::cin>>a>>b;if(a==0&&b==0)break;else std::cout<<a+b<<std::endl;}return 0;
}
while True:try:a,b = map(int,input().split())if a==b==0:breakelse:print(a+b)except EOFError:pass

04

在这里插入图片描述

#include <iostream>
using namespace std;int main(){while(true){int n;cin>>n;if (n==0)break;else{int a[n];int sum=0;for(int i=0;i<n;++i){cin>>a[i];sum = a[i]+sum;}cout<<sum<<endl;}
}return 0;
}
while True:ls=input().split()if int(ls[0]) == 0:breakelse:nums = list(map(int,ls[1:]))ans = sum(nums)print(ans)

注意:

  • python的列表 nums = list(map(int,ls[1:]))
  • 可以使用sum函数

05

在这里插入图片描述

#include <iostream>
using namespace std;int main()
{int a,b;while(cin>>a>>b){cout<<a+b<<endl;cout<<endl;}return 0;
}
try:while True:a, b = map(int, input().split())print(a + b)print()
except EOFError:pass

注意:

  • C++输出空行:cout<<endl;
  • Python输出空行:print()或者print(’ ')

06

在这里插入图片描述
在这里插入图片描述

#include <iostream>
using namespace std;int main() {int N;cin >> N; // 读取N的值for (int i = 0; i < N; ++i) {int M;cin >> M; // 读取M的值int sum = 0;for (int j = 0; j < M; ++j) {int num;cin >> num; // 读取M个整数sum += num; // 累加每个整数}cout << sum << endl; // 输出M个整数的和if (i != N - 1) {cout << endl; // 每组输出之间输出一个空行,但最后一组不输出空行}}return 0;
}
while True:try:n = int(input())while n > 0:n -= 1 nums = list(map(int,input().split()))ans = sum(nums[1:])print(ans)if n != 0:print()except:break

注意:

  • 使用数组记得要先定义n,m并且获得输入,再定义数组。
http://www.lryc.cn/news/299746.html

相关文章:

  • 2023全球云计算市场份额排名
  • Oracle数据库
  • Spring Cloud Hystrix 参数配置、简单使用、DashBoard
  • 阿里云服务器4核16G配置报价和CPU内存性能参数表
  • 数据结构:图文详解 队列 | 循环队列 的各种操作(出队,入队,获取队列元素,判断队列状态)
  • Debezium发布历史130
  • 【笔记】Harmony学习:下载安装 DevEco Studio 开发工具IDE
  • Electron实战之入门
  • 飞机大作战(c语言)
  • 服务器操作系统windows和linux区别对比
  • 吉他学习:识谱,认识节奏,视唱节奏,节拍器的使用
  • [前端开发] JavaScript基础知识 [下]
  • 新版UI界面影视小程序亲测无问题带详细搭建教程
  • 2024.2.7日总结(小程序开发4)
  • 每日五道java面试题之java基础篇(七)
  • 树莓派4B(Raspberry Pi 4B)使用docker搭建单机版nacos [基于docker-compose]
  • DAY50:完全背包、爬楼梯、322、279
  • MySQL性能调优篇(3)-缓存的优化与清理
  • Zig、C、Rust的Pk1
  • 如何用 ChatGPT 做项目管理?
  • DS:树及二叉树的相关概念
  • MATLAB | 情人节画个花瓣venn图?
  • [日常使用] Shell常用命令
  • QT+OSG/osgEarth编译之八十七:osgdb_p3d+Qt编译(一套代码、一套框架,跨平台编译,版本:OSG-3.6.5插件库osgdb_p3d)
  • 寒假 day13
  • 探索微信小程序的奇妙世界:从入门到进阶
  • 容器库(4)-std::forward_list
  • Netty Review - 服务端channel注册流程源码解析
  • 冒泡排序平均需要跑多少趟:拉马努金Q函数初探
  • Shell 学习笔记(三)-shell变量