Day 1 (2022.4.16)

bool       false/true      1byte
char       'a','\n'        1byte
int        -2^31 ~ 2^31-1  4byte
float      1.23, 1.24e2    4byte    (6-7位有效数字)
double     1.23, 1.24e2    8byte    (15-16位有效数字)  long long  -2^63 ~ 2^63-1  8byte
long double                16byte   (18-19位有效数字)  / ************************************************* /int: %d
float: %f
double: %lf
char: %c
long long: %lld/ ************************************************* /C++取模的符号适合前面的数有关 5%2==1, -5%2==-1/ ************************************************* /// cin cout 在头文件iostream
// printf scanf 在头文件cstdio#include <iostream>using namespace std;int main(){int a, b;cin >> a >> b;cout << a + b << endl;return 0;
}
// 只用scanf可以不用std命名空间#include <cstdio>int main(){int a, b, c, d;scanf("%d%d%d%d", &a, &b, &c, &d);printf("DIFERENCA = %d\n", a*b - c*d);return 0;
}

Day 2 (2022.4.17)

// string在iostream库有,且只能用cin读
// abs也在iostream库#include <iostream>using namespacestd;int main(){double basic, sale;string name;cin >> name;scanf("%lf%lf", &sale, &basic);printf("TOTAL = R& %.2lf\n", basic + 0.15*sale);return 0;
}

#include <iostream>using namespace std;int main(){double money;cin >> money;int t = money*100;printf("NOTAS:\n");printf("%d nota(s) de R$ 100.00\n", t/10000); t %= 10000;printf("%d nota(s) de R$ 50.00\n", t/5000); t %= 5000;printf("%d nota(s) de R$ 20.00\n", t/2000); t %= 2000;printf("%d nota(s) de R$ 10.00\n", t/1000); t %= 1000;printf("%d nota(s) de R$ 5.00\n", t/500); t %= 500;printf("%d nota(s) de R$ 2.00\n", t/200); t %= 200;printf("MOEDAS:\n");printf("%d moeda(s) de R$ 1.00\n", t/100); t %= 100;printf("%d moeda(s) de R$ 0.50\n", t/50); t %= 50;printf("%d moeda(s) de R$ 0.25\n", t/25); t %= 25;printf("%d moeda(s) de R$ 0.10\n", t/10); t %= 10;printf("%d moeda(s) de R$ 0.05\n", t/5); t %= 5;printf("%d moeda(s) de R$ 0.01\n", t/1);return 0;
}

Day 3 (2022.4.18)

// min和max在algorithm,pow在cmath#include <iostream>using namespace std;int main()
{double a, b, c;cin >> a >> b >> c;if (a < b) swap(a, b);if (a < c) swap(a, c);if (b < c) swap(b, c);if (a >= b + c) cout << "NAO FORMA TRIANGULO" << endl;else{if (a * a == b * b + c * c) cout << "TRIANGULO RETANGULO" << endl;if (a * a > b * b + c * c)cout << "TRIANGULO OBTUSANGULO" << endl;if (a * a < b * b + c * c) cout << "TRIANGULO ACUTANGULO" << endl;if (a == b && a == c) cout << "TRIANGULO EQUILATERO" << endl;else if (a == b || a == c || b == c) cout << "TRIANGULO ISOSCELES" << endl;}return 0;
}

Day 4 (2022.4.19)

// 大多数头文件<xxx.h>都可以用<cxxx>替代// 字符串就是字符数组加上结束符'\0'
// 可以使用字符串来初始化字符数组,但由于每个字符串结尾都会含一个'\0'字符,
// 因此字符数组的长度至少要比字符串的长度多 1char a1 = {'C', '+', '+', '\0'};
char a2[4] = "C++";// C串的读入和输出
char s[100];
scanf("%s", s)                 //以空格分开
fgets(s, 100, stdin);          //读入一行
puts(s);                       //自动换行
printf("%s\n", s);// string的读入和输出
string s;
getline(cin, s);
std::cout << s;// C串的函数
strlen(a);                     //求a的长度
strcpy(a, b);                  //将b复制给a
strcmp(a, b);                  //a<b返回-1,a=b等于0,a>b返回1//当把string对象和字符字面值及字符串字面值混在一条语句,必须确保每个加法运算符的两侧的运算对象至少有一个是string
string s1 = "12";
string s2 = '3' + "45" + s1;   //错误,不能够将字面值直接相加
// cin >> x 是会返回值的,如果读到文件末尾返回EOF
// 逗号表达式的值等于最后一个值#include <iostream>using namespace std;int main(){int x;while (cin >> x, x){for (int i = 1; i <= x; i++) cout << i << ' ';cout << endl;}return 0;
}
// 一直读可以用代码 while (cin >> x)
while (scanf("%d",&x)!=-1)// scanf在读入字符时,不会自动过滤空格、回车和Tab
// 当输入为 a = 1, b = 2, 可以用scanf读入
scanf("a = %d b = %d", &a, &b)
#include <cstdio>int main(){int arr[10];for (int i=0; i<10; i++) scanf("%d", &arr[i]);for (int i=0; i<10; i++){if (arr[i]<=0) arr[i] = 1;}for (int i=0; i<10; i++) printf("X[%d] = %d\n", i, arr[i]);return 0;
}

Day 5 (2022.4.25)

// acwing 756. 蛇形矩阵#include <iostream>using namespace std;const int N = 110;int q[N][N];
int n, m;int main(){cin >> n >> m;int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};int x = 0, y = 0, d = 0;for (int i=1; i<=n*m; i++){q[x][y] = i;int a = x + dx[d], b = y + dy[d];if (a>=n || a<0 || b>=m || b<0 || q[a][b]){d = (d + 1) % 4;a = x + dx[d], b = y + dy[d];}x = a, y = b;}for (int i=0; i<n; i++){for (int j=0; j<m; j++){cout << q[i][j] << " ";}cout << endl;}return 0;
}

Day 6 (2022.4.26)

// AcWing 760. 字符串长度 #include <iostream>using namespace std;int main(){string str;getline(cin, str);cout << str.size() << endl;return 0;
}
// AcWing 760. 字符串长度#include <cstdio>int main(){char str[101];// fgets函数会把回车也读进来    fgets(str, 101, stdin);int len = 0;for (int i = 0; str[i] && str[i] != '\n'; i++) len++;printf("%d", len);return 0;
}
AcWing 763. 循环相克令

// AcWing 765. 字符串加空格
// string 默认初始化为""#include <iostream>using namespace std;int main()
{string a, b;getline(cin, a);for (char c : a) b = b + c + ' ';// 删掉最后一个字符b.pop_back();cout << b;return 0;
}
// AcWing 769. 替换字符#include <cstdio>
#include <iostream>using namespace std;int main(){char str[31], c;scanf("%s", str);scanf("\n%c", &c);for (int i=0; str[i]; i++){if (str[i] == c) str[i] = '#';}puts(str);return 0;}
// AcWing 773. 字符串插入#include <iostream>using namespace std;int main()
{string a, b;while (cin >> a >> b){int p = 0;for (int i = 1; i < a.size(); i++){if (a[i] > a[p]) p = i;}cout << a.substr(0, p + 1) + b + a.substr(p + 1) << endl;}return 0;
}

Day 7 (2022.4.27)

// AcWing 768. 忽略大小写比较字符串大小#include <cstdio>
#include <cstring>int main()
{char a[100], b[100];fgets(a, 100, stdin);fgets(b, 100, stdin);if (a[strlen(a)-1] == '\n') a[strlen(a)-1] = 0;if (b[strlen(b)-1] == '\n') b[strlen(b)-1] = 0;for (int i = 0; a[i]; i++){if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 32;}for (int i = 0; b[i]; i++){if (b[i] >= 'A' && b[i] <= 'Z') b[i] += 32;}int t = strcmp(a, b);if (t == 0) puts("=");else if (t < 0) puts("<");else puts(">");return 0;
}
#include <iostream>using namespace std;int main()
{string a, b;getline(cin, a);getline(cin, b);for (auto &c : a) c = tolower(c);for (auto &c : b) c = tolower(c);if (a == b) puts("=");else if (a > b) puts(">");else puts("<");return 0;
}
// AcWing 767. 信息加密#include <iostream>using namespace std;int main()
{string s;getline(cin, s);for (auto &c : s)if (c >= 'a' && c <= 'z') c = (c - 'a' + 1) % 26 + 'a';else if (c >= 'A' && c <= 'Z') c = (c - 'A' + 1) % 26 + 'A';cout << s << endl;return 0;
}

Day 8 (2022.4.28)

#include <iostream>
#include <sstream>using namespace std;int main()
{string s, a, b;getline(cin, s);cin >> a >> b;stringstream ssin(s);string str;while(ssin >> str){if (str == a) cout << b << " ";else cout << str << " ";}return 0;
}
#include <iostream>using namespace std;int main()
{int n;cin >> n;while (n -- ){string str;cin >> str;int cnt = 0;char c;for (int i = 0; i < str.size(); i ++ ){int j = i;while (j < str.size() && str[j] == str[i]) j ++ ;if (j - i > cnt) cnt = j - i, c = str[i];i = j - 1;}cout << c << ' ' << cnt << endl;}return 0;
}

Day 9 (2022.5.2)

// AcWing 774. 最长单词#include <iostream>using namespace std;int main()
{string s, word;while(cin >> s){if (s.back() == '.') s.pop_back();if (s.size() > word.size()) word = s;}cout << word << endl;return 0;
}
// AcWing 775. 倒排单词#include <iostream>using namespace std;int main()
{string s[100];int n = 0;while(cin >> s[n]) n++;for (int i = n - 1; i>=0; i--){cout << s[i] << ' ';}return 0;
}
// AcWing 776. 字符串移位包含问题#include <iostream>
#include <algorithm>using namespace std;int main()
{string a, b;cin >> a >> b;if (a.size() < b.size()) swap(a, b);for (int i = 0, len = a.size(); i < len; i++){a = a.substr(1) + a[0];if (a.find(b) != string::npos){cout << "true";return 0;}}cout << "false";return 0;}

Day 10 (2022.5.8)

// 函数重载:只和函数参数(个数,类型和顺序有关)
// 传参多维数组只能省略第一维个数
// AcWing 778. 字符串最大跨距#include <iostream>using namespace std;int main()
{string s, a, b;char c;while (cin >> c, c != ',') s += c;while (cin >> c, c != ',') a += c;while (cin >> c) b += c;int l, r;l = s.find(a);r = s.rfind(b);if (l != -1 && r != -1 && l + a.size() - 1 < r) cout << r - l - a.size();else cout << -1;return 0;}
// AcWing 779. 最长公共字符串后缀#include <iostream>using namespace std;int main()
{int n;while(cin >> n, n != 0){int m_max = 0x3f3f3f3f;string s;cin >> s;for (int i = 1; i < n; i++){int t_max = 0;string compare;cin >> compare;for (int len_s = s.size() - 1, len_com = compare.size() - 1; len_s >= 0 && len_com >= 0; len_s--, len_com--){if (s[len_s] == compare[len_com]) t_max++;else break;}m_max = min(m_max, t_max);}if (m_max) cout << s.substr(s.size() - m_max) << endl;else cout << endl;}return 0;
}

Day 11 (2022.5.9)

// AcWing 809. 最小公倍数#include <iostream>using namespace std;int gcd(int a, int b)
{return b ? gcd(b, a % b) : a;
}int lcm(int a, int b)
{return a * b / gcd(a, b);
}int main()
{int a, b;cin >> a >> b;cout << lcm(a, b) << endl;return 0;
}
// AcWing 818. 数组排序#include <iostream>
#include <algorithm>using namespace std;const int N = 1010;int main()
{int n, l, r, a[N];cin >> n >> l >> r;for (int i = 0; i < n; i++) cin >> a[i];sort(a + l, a + r);for (int i = 0; i < n; i++) cout << a[i] << " ";return 0;
}
// AcWing 823. 排列#include <iostream>using namespace std;int n;
const int N = 10;void dfs(int u, int nums[], bool st[])
{if (u == n){for (int i = 0; i < n; i++) cout << nums[i] << " ";cout << endl;}else{for (int i = 1; i <= n; i++){if (!st[i]){nums[u] = i;st[i] = true;dfs(u + 1, nums, st);st[i] = false;}}}
}int main()
{cin >> n;int nums[N];// 这里 {0} 是一个0初始化器bool st[N] = {0};dfs(0, nums, st);return 0;
}

Day 12 (2022.5.12)

// 结构体和类只有一点不同,结构体默认是public,类默认private// 结构体初始化struct Person
{int age, height;double money;
}Person p = {18, 178, 100};
// 头节点一般说的是第一个节点的地址#include <iostream>using namespace std;struct Node
{int val;Node* next;Node(int _val) : val(_val), next(NULL) {}
};int main()
{Node node = Node(1);          // 定义一个节点Node* p = &node;              // 习惯用指针描述它,所以定义一个结构体指针Node* p = new Node(1);        // 直接生成一个结构体,返回结构体地址
}
// AcWing 35. 反转链表​/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode(int x) : val(x), next(NULL) {}* };*/class Solution {
public:ListNode* reverseList(ListNode* head) {if (!head || !head->next) return head;ListNode* p = head, *q = p->next;while(q){ListNode* r = q->next;q->next = p;p = q, q = r;}head->next = NULL;return p;}
};​
// AcWing 29. 删除链表中重复的节点class Solution {
public:ListNode* deleteDuplication(ListNode* head) {ListNode *fiction = new ListNode(-1);fiction->next = head;ListNode *p = fiction;while(p->next){ListNode *q = p->next;while (q->next && q->next->val == p->next->val) q = q->next;if (q == p->next) p = q;else p->next = q->next;}return fiction->next;}
};

Day 13 (2022.5.14)

// STL、位运算和常用库函数

- 第8讲 STL - AcWing

- 第9讲 位运算与常用库函数 - AcWing

// AcWing 75. 和为S的两个数字class Solution {
public:vector<int> findNumbersWithSum(vector<int>& nums, int target) {unordered_set<int> s;for (int x : nums){if (s.count(target - x)) return {x, target - x};else s.insert(x);}}
};
// AcWing 51. 数字排列class Solution {
public:vector<vector<int>> permutation(vector<int>& nums) {sort(nums.begin(), nums.end());vector<vector<int>> res;do res.push_back(nums); while (next_permutation(nums.begin(), nums.end()));return res;}
};
// AcWing 862. 三元组排序#include <iostream>
#include <algorithm>
#include <vector>using namespace std;struct three_Pair{int x;double y;string s;bool operator< (const three_Pair &t) const{return x < t.x;}
};int main()
{three_Pair p[10001];int n;cin >> n;for (int i = 0; i < n; i++){cin >> p[i].x >> p[i].y >> p[i].s;}sort(p, p+n);for (int i = 0; i < n; i++)printf("%d %.2lf %s\n", p[i].x, p[i].y, p[i].s.c_str());return 0;
}

C++ 基础语法课 - AcWing相关推荐

  1. 风变编程python助教_花30天时间,学完了风变编程Python基础语法课

    原标题:花30天时间,学完了风变编程Python基础语法课 20节实打实的课程,1个月时间,我终于学完了风变编程的Python基础语法课.刚开始学的时候,就有人问我感受怎么样,当时本着未知全貌不予置评 ...

  2. 风变编程python课_花30天时间,学完了风变编程Python基础语法课

    原标题:花30天时间,学完了风变编程Python基础语法课 20节实打实的课程,1个月时间,我终于学完了风变编程的Python基础语法课.刚开始学的时候,就有人问我感受怎么样,当时本着未知全貌不予置评 ...

  3. 风变python小课 基础语法12 作业1_菜鸟的风变编程Python小课之路,这么学编程也可以?...

    原标题:菜鸟的风变编程Python小课之路,这么学编程也可以? 作为职场菜鸟,我感觉我就是现实生活里的孙弈秋,虽然学历没有他那么惨,但是在公司总感觉不那么受待见,可能因为我们这个行业本身竞争大吧,领导 ...

  4. python使用缩进作为语法边界-重庆铜梁高校邦数据科学通识课【Python基础语法】答案...

    重庆铜梁高校邦数据科学通识课[Python基础语法]答案it8p 重庆铜梁高校邦数据科学通识课[Python基础语法]答案 关注公众号{帅搜}即可查询答案 支持:网课,智慧树,知到,超星,尔雅,学习通 ...

  5. python基础语法 第0关print-徐州鼓楼高校邦数据科学通识课【Python基础语法】答案...

    徐州鼓楼高校邦数据科学通识课[Python基础语法]答案it8p 徐州鼓楼高校邦数据科学通识课[Python基础语法]答案 关注公众号{帅搜}即可查询答案 支持:大学网课,智慧树,知到,超星,尔雅,学 ...

  6. python基础语法 第0关print-重庆酉阳高校邦数据科学通识课【Python基础语法】答案...

    重庆酉阳高校邦数据科学通识课[Python基础语法]答案it8p 重庆酉阳高校邦数据科学通识课[Python基础语法]答案 关注公众号{帅搜}即可查询答案 支持:大学网课,智慧树,知到,超星,尔雅,学 ...

  7. python基础语法 第0关print-温州文成高校邦数据科学通识课【Python基础语法】答案...

    温州文成高校邦数据科学通识课[Python基础语法]答案it8p 温州文成高校邦数据科学通识课[Python基础语法]答案 关注公众号{帅搜}即可查询答案 支持:网课,智慧树,知到,超星,尔雅,学习通 ...

  8. 基于python物流管理系统毕业设计-长白高校邦数据科学通识课【Python基础语法】答案...

    长白高校邦数据科学通识课[Python基础语法]答案it8p 长白高校邦数据科学通识课[Python基础语法]答案 关注公众号{帅搜}即可查询答案 支持:网课,智慧树,知到,超星,尔雅,学习通,选修课 ...

  9. python代码块所属关系的语法-天元高校邦数据科学通识课【Python基础语法】答案...

    天元高校邦数据科学通识课[Python基础语法]答案it8p 天元高校邦数据科学通识课[Python基础语法]答案 关注公众号{帅搜}即可查询答案 支持:大学网课,智慧树,知到,超星,尔雅,学习通,选 ...

最新文章

  1. 更好的Java虚拟机Zing: 更好的性能,无停顿,更快的启动
  2. znet zbus 子项目
  3. Nature: 人的肠道古细菌基因组集
  4. 解决apache配置问题小结
  5. Java注解Annotation的基本概念
  6. Python--一些重要的小tips【持续更新】
  7. Jmeter之断言操作
  8. 11月11日:一个人的情人节
  9. 《JavaScript高级程序设计》读书笔记 ---if语句
  10. ajax url 的是什么格式,什么是从AJAX URL格式来发送POST方法有响应实体
  11. inventor 波纹阵列_Inventor技巧之草图驱动的阵列图文教程
  12. idea actiBPM插件生成png文件 (解决没有Diagrams或Designer选项问题)
  13. 国联安 德盛 新基金 申购免手续费 产品好 利润高
  14. mybatis连接池
  15. 软件视频会议系统 服务器要求,视频会议系统招标要求.docx
  16. 《红楼梦》的香气韵调
  17. std::packaged_task 源码分析
  18. 转:数据之美:迄今 10 佳数据可视化示例
  19. 成都理工大学计算机考研经历,09计算机考研的小小体会~
  20. k8s 1.24.0版本使用nfs-provisioner4.0.0动态创建PV

热门文章

  1. 欢乐Flash夏令营
  2. php免费编辑工具,10个免费的PHP编辑器/开发工具_PHP教程
  3. 论文 基于度量学习的小样本学习研究 阅读心得
  4. 微信小程序picker组件实现多列选择器
  5. c语言rtrim函数返回值,C语言的Trim, LTrim, RTrim
  6. 企业如何在新兴成长型产业中脱颖而出
  7. memset函数的用法
  8. CUDA版本与显卡驱动对照表
  9. 阿里云Aliware首批“铂金合作伙伴”花落谁家?——北京天源迪科当之无愧!!!...
  10. .proto 文件转成 lua 文件完整版(Windows 下)