6.文字处理软件
题目:代码:
include include includeusing namespace std;
int amount,num;string first,last;
void insertlast(){ string str; cin>>str; last = last.append(str);//知识点1 cout<
5.标题统计
题目:代码:
include include includeusing namespace std;
int main(){ string s; getline(cin,s); //知识点1 int length = s.size(); for(int i = 0; i < s.size(); i++){ if(s[i] - 32 == 0 || s[i] == ‘\n’){ length—; } } cout<<length; return 0;}官方代码:
includeusing namespace std;int main(){ int ans=0; char c; if(cin>>c)ans++; //cin自动去除空格换行 if(cin>>c)ans++; //cin在读不到数据时返回0 if(cin>>c)ans++; //因为题目规定标题不超过5个字符,所以可这样做 if(cin>&g ...
7.统计单词数
题目:代码:
include include include using namespace std;
int main(){ string intend,passage; int num = 0,first = 0; getline(cin,intend); getline(cin,passage);//输入 for(int i = 0; i < intend.size();i++){ intend[i] = tolower(intend[i]); } for(int i = 0; i < passage.size();i++){ passage[i] = tolower(passage[i]); }//统一格式 intend = intend.append(“ “); //a=’ ‘+a+’ ‘; b=’ ‘+b+’ ‘;//简单写法 intend = intend.insert(0,” “); ...
洛谷-题单-字符串入门
C语言字符串函数:头文件:#include 1.stpcpy作用:复制字符串用法:stpcpy(目标串变量,被复制字符串变量);2.strcat作用:拼接字符串用法:strcat(目标串变量,被拼接字符串变量)3.strchr作用:用法:4.作用:用法:5.作用:用法:
C++知识点一.string类作用:约等于char,是 C++用来代替 char 数组的数据结构,且是动态变化的,不用对大小进行约束
结构:是一个类,为一个顺序表,类的内部封装了char*
在使用string类时,必须包含 #include 头文件以及 using namespace std
用法:一. string的构造函数的形式:string str:生成空字符串
string s(str):生成字符串为str的复制品
string s(str, strbegin,strlen):将字符串str中从下标strbegin开始、长度为strlen的部分作为字符串初值
string s(cstr, char_len):以C_string类型cstr的前char_len个字符串作为字符串s的初值
string s(num ...
洛谷-题单-字符串入门-代码
题目:自动修正
include include using namespace std;
int main(){ string s; cin>>s; for(int i = 0; i < s.length();i++){ s[i] = toupper(s[i]); } cout<=’a’ && a[i]<=’z’){ a[i]=a[i]-‘a’+’A’; //a[i]=a[i]- (‘a’ - A)}把大写转换成小写就是:
if(a[i]>=’A’ && a[i]<=’Z’){ a[i]=a[i]-‘A’+’a’;}
题目:小书童-凯撒密码c++最终版本:
include include using namespace std;
int main(){ string s; int n; cin>>n>>s; if(n >0&&n <27){ for(int i = 0 ...
1.差值
题目:D:\hexo\heo\source_posts\练习题\牛客\pic-牛客\1.差值.png代码:
include include include using namespace std;
int main(){ int n; int c = 1000000; cin>>n; //输入战士数量 int zl[n - 1]; for(int i = 0; i < n; i++){ cin>>zl[i]; } //输入战力 sort(zl, zl + n); //知识点1 for(int i = 0; i < n - 1; i++){ c = abs(zl[i] - zl[i + 1]) < c ? abs(zl[i] - zl[i + 1]) : c; //知识点2 if(c == 0) break; } cout<<c; return 0;}
知识点:1.排序c++ sort()用法:sort(begin, ...
2.删除公共字符
题目:代码:
include include using namespace std;//没有要求大小写 所以没做出说明int main(){ string str1,str2; getline(cin,str1); cin>>str2; for(int i = 0; i < str2.size();i++){ int pos = str1.find(str2[i]); while(pos >= 0){ str1 = str1.erase(pos,1); //知识点1 pos = str1.find(str2[i]); } } cout<
LeeCode-02-跳跃游戏2
int jump(int nums, int numsSize) { / 思路: 1.都是从0开始,所以maxlength = 0,每跳跃一次,遍历从index = 0到index = nums[i],即这一次所能跳跃最大距离的所有的元素,判断跳跃这一 次所到达的最远距离,更新maxlength,以此类推,直至maxlength >= numsSize - 1 */ int maxlength = nums[0]; int amount = 0;
if(numsSize == 1){
return amount;
}
if (maxlength >= numsSize - 1){
return amount + 1;
}
/*for(int i = 0; i < numsSize; i++){
for(int j = i + 1; j <= i + nums[i]; j++){
if(j == numsSiz ...
LeeCode-02-跳跃游戏1
题目描述:解题:法一:超越时间限制bool canJump(int nums, int numsSize) { / 题目理解: 目的:从nums[0]跳到nums[numsSize - 1] 约束:跳跃长度jumplength <= nums[pos] pos:当前数组元素下标 目标:如果可以达到目的 跳跃次数 越少越好 否则输出false 特殊点: 1.nums[pos] = 0 && pos < numsSize - 1 2.不满足跳到最后的条件: 1> 总会到达跳跃长度为0的下标 思路: 1.跳过nums[pos] = 0 && pos < numsSize - 1的数组元素 2.减少跳跃次数
思路2:判断如何从nums[0]跳到跳跃长度为0的下标,能找到输出false,否则输出true
1.遍历数组,找到nums[pos] = 0的pos
思路3:只要能找到一条跳到nums[numsSize - 1]的路,能找到输出true,否则输出false
1 ...
算法-01-贪心算法1-Djikstra算法
贪心算法:寻找局部最优解大概有两种方法:Djikstra算法(迪杰斯特拉算法) 最小生成树Prim算法Djikstra算法