首页 > TAG信息列表 > StOI

1110 区块反转 测试点分析 测试点1、2、4

易错点 测试点1、4:结点数量n和区块结点数k满足(n-1)%k==0的情况 测试点2:k为1的情况 如输入为:“00100 2 1 00100 1 12309 12309 2 -1” 代码 #include <iostream> #include <cstdio> #include <string> using namespace std; int a[100001]; string nxt[100001]; string p[100001];

1105 链表合并

代码 #include <iostream> #include <cstdio> #include <string> using namespace std; int a[100000]; string nxt[100000]; string p1[100000]; string p2[100000]; int main() { string addr1,addr2; int n; string address,naddress; int data; st

2021CCCC天梯赛L1-075

#include<iostream> using namespace std; int main() { string s; cin>>s; if(s.size()==4) { int a=stoi(s.substr(0,2)); int b=stoi(s.substr(2,2)); if(a<=21)printf("20%02d-%02d",a,b); el

1110 Complete Binary Tree (25 分)【难度: 一般 / 知识点: 判断完全二叉树】

https://pintia.cn/problem-sets/994805342720868352/problems/994805359372255232 建树并给其赋值,如果是完全二叉树,那么maxid一定为n,否则则不是完全二叉树。 找根节点,就找到入度为0的点就是根节点。 #include<bits/stdc++.h> using namespace std; int l[30],r[30]; int n

c++中的atoi()和stoi()函数的用法和区别

相同点: ①都是 C++ 的字符处理函数,把数字字符串转换成 int 输出 ②头文件都是 #include<cstring> 不同点: ①atoi() 的参数是 const char* ,因此对于一个字符串 str 我们必须调用 c_str() 的方法把这个 string  转换成 const char* 类型的,而 stoi() 的参数是 const string& ,不

累加数

    变量简洁正确完整思路 dfs,全局ok判断 fori作为第二个开头,forj作为第二个结尾,计算后从k=j+1开始找, <add就继续找,=add dfs,>addreturn,以下是未处理溢出的初步代码,防止前置0用了很多continue class Solution { public: bool ok=false; bool isAdditiveNumber(string

字符串和整数之间的转换

一、使用stringstream 类c++中的 <sstream>库定义了三种类:istringstream、ostringstream和stringstream,分别用来进行流的输入、输出和输入输出操作。         二、c++中 stoi将 n 进制的字符串转化为十进制示例:stoi(str, 0, 2); //将字符串 str 从 0 位置开始到末尾的 2 进

C++ atoi和stoi

在做算法题的时候,如果char转为int只需要 c - '0’即可得到对应数字。 但是遇到string类型需要转化为数字就可以调用函数 atoi 和 stoi 通常用法 string a = "3"; int num1 = atoi(a.c_str()); string b = "3"; int num2 = stoi(b); 头文件 include<cstring> 区别: 1. at

leetcode7:整数反转

0x00:问题描述   将一int型数字实现高低位反转,若遇到反转后的数值超出int型变量表示范围则返回0值。   原题链接:https://leetcode-cn.com/problems/reverse-integer/ 0x01:解题思路   由于数字反转后数值大小可能超限,故采用字符串的形式进行反转处理会比较方便。   此处用

PAT(Advanced Level)A1132. Cut Integer

题意 将一个长度为K的数字Z对半分,前半部分和后半部分各自构成了A和B两个数字,问A*B是否为Z的因子 思路 模拟题,说得很清楚了,我们把数字当作字符串来处理,结合stoi()函数会很方便 ⚠️注意取余操作是不能对0取余的 代码 #include <iostream> #include <algorithm> #include <unordered

1132 Cut Integer (20 分)

水~。 注意右半部为\(0\)的情况。 int main() { int T; cin>>T; while(T--) { string s; cin>>s; string a=s.substr(0,s.size()/2),b=s.substr(s.size()/2); int ts=stoi(s),ta=stoi(a),tb=stoi(b); if(tb &

PAT(乙级)2020年秋季考试(模拟赛)

PAT(乙级)2020年秋季考试 7-1 多二了一点 (15分)7-2 数字之王7-3如需挪车请致电7-4 胖达与盆盆奶7-5 买地攻略 7-1 多二了一点 (15分) 7-1 多二了一点 (15分) 若一个正整数有 2n 个数位,后 n 个数位组成的数恰好比前 n 个数位组成的数多 2,则称这个数字“多二了一点”。如 24

入门篇(1)-入门模拟-简单模拟-Codeup习题-问题B:A+B

问题B:A+B 题目描述 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。 现在请计算A+B的结果,并以正常形式输出。 输入 输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。 输出 请计算A+B的结果,并以正常形式输出,每组数据占一行。 样例输入 -

1069 The Black Hole of Numbers (20 分)

注意不满\(4\)位的话要补成\(4\)位。 string s; set<int> S; int main() { cin>>s; while(s.size()<4) s='0'+s; while(true) { sort(s.begin(),s.end(),greater<char>()); string sa=s; reverse(s.begin(

类型转换

【字符串转数字】从前往后逐个变换 int a=0; for(int i=0;i<strlen(chr);i++) { a=a*10+(chr[i]-'0'); } 【字符串转数字】从后往前使用pow逐个变换 #include <cmath> int count=0,a=0; for(int i=strlen(chr);i>=0;i--) { a+=pow(10,count++)*(chr[i]-'0')

「StOI-1」IOI计数

[洛谷链接](https://www.luogu.com.cn/problem/P6373) 题目背景 蒻L_C_A想了解一下IOI,可他太菜了,看不懂题目,只会数数。 题目描述 给定一个长度为 nn 字符串 SS ,同时进行 mm 次操作: 操作1:11 xx cc 表示将第 xx 个字符改为 cc( cc 只会为 I 或 O )。 操作2:22 ll rr 询问字符串 SS 中有

CSP 201712-3 Crontab(0→85→95→100)

CSP 201712-3 Crontab 0→85→95→100 3 Crontab题面链接题意思路源码 3 Crontab tag:复杂模拟 字符串 日期 题面链接 http://118.190.20.162/view.page?gpid=T66. 题意   题目为任务的调度问题,个人感觉跟平常使用的日历中的日程计划比较类似。题目会给出多个任务以及

luogu P6373 【「StOI-1」IOI计数】

官方题解对于思路的讲述已经非常的清晰了. 分享一个个人心得: 线段树对于左右区间的运用 线段树主要就是妙在它的合并区间功能以及对于一个整块进行分治的思想.你会发现,每次线段树的更新基本上都是基于左右儿子这两个左右区间的.对于可以区间维护的信息(基本上也就是可以分裂成子

PAT 1002 写出这个数

PAT 1002 写出这个数 题目: 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10100。 输出格式: 在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音

PAT Advanced 1132 Cut Integer (20分)

Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of A and B

字符串处理 pat1132

//1132 //substr(a,b) a 为起始位置,b 为个数 //用于截取字符串 #include <iostream> #include<stdio.h> #include<string> #include<algorithm> #include<string.h> using namespace std; int main() { freopen("1132.txt","r",

C++中stoi函数

作用:   将 n 进制的字符串转化为十进制 头文件: #include <string> 用法: 1 stoi(字符串,起始位置,n进制),将 n 进制的字符串转化为十进制2 3 示例:4 stoi(str, 0, 2); //将字符串 str 从 0 位置开始到末尾的 2 进制转换为十进制 但好像不是标准函数,慎用吧。 案例: 1 #include <ios

对称平方数(to_string函数,stoi函数真香)

题目描述 打印所有不超过n(n<256)的,其平方具有对称性质的数。如11*11=121。 输入描述: 无 输出描述: 每行一个数,表示对称平方数。 示例1 输入 复制 无 输出 复制 无解题思路:利用c++的字符串进行数和字符串进行转换本质还是回文数的判断而已 #include <iostream>#include <c

关于杭电2029题Identity Card不能AC的疑惑

关于杭电2029题Identity Card不能AC的疑惑 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=2&problemid=25 以下是我的代码: #include<iostream> #include<string> using namespace std; int main(){ int n,i; string s,place; cin>