课评: 转出学生归档(王子墨/张立坤/黄俊博)+ 周四班级总结 + 新生章梓皓档案 + C++示例代码
This commit is contained in:
52
C++代码/CSP04/02-简单排序/冒泡排序.cpp
Normal file
52
C++代码/CSP04/02-简单排序/冒泡排序.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
void print(){
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void bubbleSort(){
|
||||
for(int i = 1; i <= n - 1; i++){ // i表示趟数
|
||||
bool ok = true; // 没有进行交换过
|
||||
for(int j = 1; j <= n - i; j++){ // 要比较的这个数的下标
|
||||
if(arr[j] > arr[j+1]){
|
||||
swap(arr[j], arr[j+1]);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if(ok){
|
||||
break;
|
||||
}
|
||||
cout << "第" << i << "趟:";
|
||||
print();
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
bubbleSort();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 时间复杂度
|
||||
// O(n*n) 最好时间复杂度 O(n) 最差时间复杂度O(n*n)
|
||||
// 稳定的排序算法
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/冒泡排序.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/冒泡排序.exe
Normal file
Binary file not shown.
42
C++代码/CSP04/02-简单排序/未命名1.cpp
Normal file
42
C++代码/CSP04/02-简单排序/未命名1.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
// 冒泡排序
|
||||
for(int i = 1; i <= n - 1; i++) { // i表示的是趟数
|
||||
bool ok = true; // 一开始我认为没有交换
|
||||
for(int j = 1; j <= n - i; j++) { // j表示的是食指 j+1
|
||||
if(arr[j] > arr[j+1]) {
|
||||
swap(arr[j], arr[j+1]);
|
||||
ok = false; // 交换过了
|
||||
}
|
||||
}
|
||||
|
||||
cout << "第" << i << "趟:";
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
|
||||
if(ok) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "最终:";
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/未命名1.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/未命名1.exe
Normal file
Binary file not shown.
22
C++代码/CSP04/02-简单排序/未命名2.cpp
Normal file
22
C++代码/CSP04/02-简单排序/未命名2.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
|
||||
int cnt = 0;
|
||||
int curr = 1;
|
||||
|
||||
for(int i = 2; i <= n; i++){
|
||||
// 第i格有多少米
|
||||
curr = curr * 2;
|
||||
cnt += curr;
|
||||
}
|
||||
|
||||
cout << cnt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/未命名2.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/未命名2.exe
Normal file
Binary file not shown.
44
C++代码/CSP04/02-简单排序/选择排序.cpp
Normal file
44
C++代码/CSP04/02-简单排序/选择排序.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
void print(){
|
||||
for(int i = 1; i <= n; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void selectionSort(){
|
||||
for(int i = 1; i <= n - 1; i++){ // i表示要交换的这个位置
|
||||
int maxx = arr[i]; // minn是当前的最小值
|
||||
int idx = i;
|
||||
|
||||
// 找到当前这一轮的最小值
|
||||
for(int j = i + 1; j <= n; j++){
|
||||
if(arr[j] > maxx) {
|
||||
maxx = arr[j];
|
||||
idx = j;
|
||||
}
|
||||
}
|
||||
swap(arr[i], arr[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
// 时间复杂度 O(n*n)
|
||||
// 不稳定
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
selectionSort();
|
||||
print();
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/02-简单排序/选择排序.exe
Normal file
BIN
C++代码/CSP04/02-简单排序/选择排序.exe
Normal file
Binary file not shown.
28
C++代码/CSP04/03-二维数组/01矩阵原样输出.cpp
Normal file
28
C++代码/CSP04/03-二维数组/01矩阵原样输出.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100][100100];
|
||||
|
||||
int main(){
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cout << arr[i][j];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
35
C++代码/CSP04/03-二维数组/图像相似度.cpp
Normal file
35
C++代码/CSP04/03-二维数组/图像相似度.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[110][110];
|
||||
int b[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> b[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
if(a[i][j] == b[i][j]){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << fixed << setprecision(2);
|
||||
cout << 100.0 * cnt / (n * m) ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/图像相似度.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/图像相似度.exe
Normal file
Binary file not shown.
33
C++代码/CSP04/03-二维数组/未命名1.cpp
Normal file
33
C++代码/CSP04/03-二维数组/未命名1.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m, num, cnt = 0;
|
||||
int arr[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
// 第一幅图
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
// 第二幅图
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
// arr[i][j]
|
||||
cin >> num;
|
||||
if(num == arr[i][j]){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 相同的像素块有cnt个 总数 n * m 相同的像素块 / 总数
|
||||
// int z = n * m;
|
||||
cout << fixed << setprecision(2) << 100.0 * cnt / (n * m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/未命名1.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/未命名1.exe
Normal file
Binary file not shown.
39
C++代码/CSP04/03-二维数组/未命名4.cpp
Normal file
39
C++代码/CSP04/03-二维数组/未命名4.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int cnt = 0;
|
||||
int a[110][110];
|
||||
int b[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
// 第一幅画读入
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
// 第二幅图
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> b[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
// 对比两幅图的相同位置进行比较
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
if(a[i][j] == b[i][j]){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 相同点数 除 n * m
|
||||
cout << fixed << setprecision(2);
|
||||
cout << 100.0 * cnt / (n * m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/未命名4.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/未命名4.exe
Normal file
Binary file not shown.
20
C++代码/CSP04/03-二维数组/未命名5.cpp
Normal file
20
C++代码/CSP04/03-二维数组/未命名5.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int age;
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){ // 第i行的所有数据
|
||||
int maxx = 0;
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> age;
|
||||
maxx = max(age, maxx);
|
||||
}
|
||||
cout << maxx << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
22
C++代码/CSP04/03-二维数组/每个小组的最大年龄.cpp
Normal file
22
C++代码/CSP04/03-二维数组/每个小组的最大年龄.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m, age;
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
int maxx = 0;
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> age;
|
||||
maxx = max(maxx, age);
|
||||
}
|
||||
cout << maxx << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/每个小组的最大年龄.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/每个小组的最大年龄.exe
Normal file
Binary file not shown.
26
C++代码/CSP04/03-二维数组/每列最大值.cpp
Normal file
26
C++代码/CSP04/03-二维数组/每列最大值.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = 1; j <= m; j++){
|
||||
int maxx = 0;
|
||||
for(int i = 1; i <= n; i++) {
|
||||
maxx = max(maxx, a[i][j]);
|
||||
}
|
||||
cout << maxx << " ";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/每列最大值.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/每列最大值.exe
Normal file
Binary file not shown.
34
C++代码/CSP04/03-二维数组/矩阵加法.cpp
Normal file
34
C++代码/CSP04/03-二维数组/矩阵加法.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[110][110];
|
||||
int b[110][110];
|
||||
|
||||
int main(){
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> a[i][j];
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> b[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
a[i][j] += b[i][j];
|
||||
cout << a[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/矩阵加法.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/矩阵加法.exe
Normal file
Binary file not shown.
28
C++代码/CSP04/03-二维数组/矩阵原样输出.cpp
Normal file
28
C++代码/CSP04/03-二维数组/矩阵原样输出.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[110][110];
|
||||
|
||||
int main(){
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){
|
||||
cout << arr[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/CSP04/03-二维数组/矩阵原样输出.exe
Normal file
BIN
C++代码/CSP04/03-二维数组/矩阵原样输出.exe
Normal file
Binary file not shown.
26
C++代码/GESP考级/一级/202609新龟兔赛跑.cpp
Normal file
26
C++代码/GESP考级/一级/202609新龟兔赛跑.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
double wut, tuv, tut; // 乌龟到终点的时间 兔子的速度 兔子休息的时间
|
||||
cin >> wut >> tuv >> tut;
|
||||
|
||||
// 先求出兔子到终点的时间
|
||||
double t = 1000.0 / tuv + tut;
|
||||
|
||||
if(t == wut){
|
||||
cout << "tie";
|
||||
} else if(t < wut){
|
||||
cout << "rabbit";
|
||||
} else {
|
||||
cout << "turtle";
|
||||
}
|
||||
cout << endl;
|
||||
cout << fixed << setprecision(2) << t;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/一级/202609新龟兔赛跑.exe
Normal file
BIN
C++代码/GESP考级/一级/202609新龟兔赛跑.exe
Normal file
Binary file not shown.
19
C++代码/GESP考级/一级/202609棋盘上的奖赏.cpp
Normal file
19
C++代码/GESP考级/一级/202609棋盘上的奖赏.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
long long cnt = 1;
|
||||
|
||||
for(int i = 1; i <= n; i++){
|
||||
cnt = cnt * 2;
|
||||
}
|
||||
|
||||
cout << cnt - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/一级/202609棋盘上的奖赏.exe
Normal file
BIN
C++代码/GESP考级/一级/202609棋盘上的奖赏.exe
Normal file
Binary file not shown.
53
C++代码/GESP考级/三级/202609公共二进制位.cpp
Normal file
53
C++代码/GESP考级/三级/202609公共二进制位.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, num;
|
||||
int s[100];
|
||||
|
||||
string str = "01";
|
||||
|
||||
// 10进制转换成 2进制
|
||||
string f(int n){
|
||||
if(n == 0) return "0";
|
||||
string re = "";
|
||||
while(n > 0){
|
||||
int g = n % 2;
|
||||
|
||||
re = str[g] + re;
|
||||
|
||||
n /= 2;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
cin >> n;
|
||||
int maxx = 0;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> num;
|
||||
string curr = f(num);
|
||||
int len = curr.size();
|
||||
int idx = 0;
|
||||
for(int j = len - 1; j >= 0; j--){
|
||||
char c = curr[j];
|
||||
if(c == '1'){
|
||||
s[idx]++;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
maxx = max(maxx, idx); // 统计最长字符串
|
||||
// cout << "当前这个数二进制是" << curr << " " << idx << endl;
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
for(int i = 0; i < maxx; i++){
|
||||
if(s[i] == n) {
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
cout << cnt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/三级/202609公共二进制位.exe
Normal file
BIN
C++代码/GESP考级/三级/202609公共二进制位.exe
Normal file
Binary file not shown.
46
C++代码/GESP考级/三级/202609分割字符串.cpp
Normal file
46
C++代码/GESP考级/三级/202609分割字符串.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s;
|
||||
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
|
||||
int len = s.size();
|
||||
string curr = ""; // 当前这个字符串
|
||||
int k = 1; // 需要多少个空格
|
||||
int idx = 0; // 当前的下标
|
||||
|
||||
while(idx < len){
|
||||
char c = s[idx];
|
||||
if(c == ' '){
|
||||
// 当遇到空格
|
||||
string z = s.substr(idx, k);
|
||||
bool ok = true;
|
||||
for(char c1 : z){
|
||||
if(c1 != ' ') {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(ok){
|
||||
cout << curr << endl;
|
||||
idx += k;
|
||||
k++; // 下一次的空格要加一
|
||||
curr = "";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
curr += c;
|
||||
if(idx == len - 1){
|
||||
cout << curr << endl;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/三级/202609分割字符串.exe
Normal file
BIN
C++代码/GESP考级/三级/202609分割字符串.exe
Normal file
Binary file not shown.
36
C++代码/GESP考级/三级/202609分割字符串解法2.cpp
Normal file
36
C++代码/GESP考级/三级/202609分割字符串解法2.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s;
|
||||
|
||||
int main() {
|
||||
getline(cin, s);
|
||||
|
||||
int len = s.size();
|
||||
string curr = ""; // 要输出的这个字符串
|
||||
int kg = 1; // 中断的空格数量
|
||||
int cnt = 0; // 当前空格的数量
|
||||
|
||||
for(char c : s) {
|
||||
curr += c;
|
||||
if(c == ' ') {
|
||||
cnt++;
|
||||
} else {
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
if(cnt == kg) {
|
||||
cout << curr << endl;
|
||||
cnt = 0;
|
||||
kg++;
|
||||
curr = "";
|
||||
}
|
||||
|
||||
}
|
||||
if(curr.size() >= 1) {
|
||||
cout << curr << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/三级/202609分割字符串解法2.exe
Normal file
BIN
C++代码/GESP考级/三级/202609分割字符串解法2.exe
Normal file
Binary file not shown.
30
C++代码/GESP考级/三级/202609分割字符串解法3.cpp
Normal file
30
C++代码/GESP考级/三级/202609分割字符串解法3.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s;
|
||||
|
||||
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
|
||||
string kg = "";
|
||||
int l = 0, r = 0;
|
||||
|
||||
while(true){
|
||||
kg = kg + ' ';
|
||||
if(s.find(kg, l) == string::npos){
|
||||
// 如果没有找到
|
||||
r = s.size() - 1;
|
||||
cout << s.substr(l, r - l) << endl;
|
||||
break;
|
||||
} else {
|
||||
// 找到了
|
||||
r = s.find(kg, l);
|
||||
cout << s.substr(l, r - l) << endl;
|
||||
l = r + kg.size();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/三级/202609分割字符串解法3.exe
Normal file
BIN
C++代码/GESP考级/三级/202609分割字符串解法3.exe
Normal file
Binary file not shown.
23
C++代码/GESP考级/二级/202609字符变换.cpp
Normal file
23
C++代码/GESP考级/二级/202609字符变换.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int a, b, c;
|
||||
|
||||
int main(){
|
||||
cin >> a >> b >> c;
|
||||
int cnt = 0;
|
||||
for(int i = 1; i <= 8; i++){
|
||||
for(int j = 1 ;j <= 16; j++){
|
||||
cnt++;
|
||||
if(cnt == a || cnt == b || cnt == c){
|
||||
cout << (char)cnt;
|
||||
}else {
|
||||
cout << '*';
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/二级/202609字符变换.exe
Normal file
BIN
C++代码/GESP考级/二级/202609字符变换.exe
Normal file
Binary file not shown.
32
C++代码/GESP考级/二级/202609直角三角形.cpp
Normal file
32
C++代码/GESP考级/二级/202609直角三角形.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
double a, b, t;
|
||||
int cnt = 3;
|
||||
|
||||
int main(){
|
||||
cin >> a >> b >> t;
|
||||
|
||||
double curr = 0;
|
||||
|
||||
if(a > t){
|
||||
cout << 1;
|
||||
return 0;
|
||||
} else if(b > t){
|
||||
cout << 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
curr = sqrt(a * a + b * b); // µÚÈýÏî
|
||||
while(curr <= t){
|
||||
cnt++;
|
||||
a = b;
|
||||
b = curr;
|
||||
curr = sqrt(a * a + b * b);
|
||||
}
|
||||
|
||||
cout << cnt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/GESP考级/二级/202609直角三角形.exe
Normal file
BIN
C++代码/GESP考级/二级/202609直角三角形.exe
Normal file
Binary file not shown.
38
C++代码/学习/我是第几个单词.cpp
Normal file
38
C++代码/学习/我是第几个单词.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s, a; // s
|
||||
int dc = 0; // 当前是第几个单词
|
||||
int zm = 0; // 当前是第几个字母
|
||||
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
cin >> a;
|
||||
|
||||
string curr = "";
|
||||
for(char c : s){
|
||||
if(c == ' ' || c == '.'){
|
||||
// 中断
|
||||
// 出现一个单词
|
||||
// if(curr.size() == 0){
|
||||
// continue;
|
||||
// }
|
||||
dc++; // 单词数加一
|
||||
cout << curr << " ";
|
||||
if(curr == a){
|
||||
cout << dc;
|
||||
return 0;
|
||||
}
|
||||
curr = "";
|
||||
|
||||
} else {
|
||||
curr += c;
|
||||
zm++; // 字母数加一
|
||||
}
|
||||
}
|
||||
|
||||
cout << zm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/我是第几个单词.exe
Normal file
BIN
C++代码/学习/我是第几个单词.exe
Normal file
Binary file not shown.
21
C++代码/学习/未命名1.cpp
Normal file
21
C++代码/学习/未命名1.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string str;
|
||||
|
||||
int main(){
|
||||
// 两种读入
|
||||
// cin >> str; // 局限:遇到空格就结束
|
||||
|
||||
getline(cin, str);
|
||||
|
||||
// cout << str;
|
||||
|
||||
// int len = str.size(); // 字符串.size(); 可以获得字符串的长度
|
||||
for(char c : str){
|
||||
cout << c << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/未命名1.exe
Normal file
BIN
C++代码/学习/未命名1.exe
Normal file
Binary file not shown.
@@ -6,18 +6,25 @@ int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
char c;
|
||||
cin >> c;
|
||||
string str = "abacad";
|
||||
// // 截取子串 字符串.substr(pos, num) pos 想从什么位置开始截取 num截取多长
|
||||
// string sub1 = str.substr(1, 2);
|
||||
// // 截取子串 函数重载
|
||||
// string sub = str.substr(1);
|
||||
|
||||
// 判断c是大写还是小写
|
||||
if(c >= 'a' && c <= 'z'){
|
||||
// 小写
|
||||
c = c - 'a' + 'A';
|
||||
} else {
|
||||
c = c - 'A' + 'a';
|
||||
// 查找
|
||||
// 字符串.find('a');
|
||||
int idx = -1;
|
||||
while(1){
|
||||
if(idx >= str.size()) break;
|
||||
idx = str.find('a', idx + 1);
|
||||
cout << idx << " ";
|
||||
}
|
||||
|
||||
cout << c;
|
||||
// if(str.find('h') == string::npos){
|
||||
// cout << "没有出现过";
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
29
C++代码/学习/未命名3.cpp
Normal file
29
C++代码/学习/未命名3.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n;
|
||||
int arr[100100];
|
||||
|
||||
int main(){
|
||||
// 替换
|
||||
string s = "abcdef";
|
||||
|
||||
// // 字符串.replace(pos, len, newstr);
|
||||
// cout << s.replace(1, 2, "ab cd");
|
||||
//
|
||||
//// s.size() // 如果是空 false
|
||||
//// s.empty() // 判断s是不是空的 true
|
||||
//
|
||||
// // 比较大小
|
||||
// string s1 = "123", s2 = "A";
|
||||
//
|
||||
// cout << (s1 < s2); // 0
|
||||
//
|
||||
s.erase(1, 2);
|
||||
|
||||
cout << s;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
C++代码/学习/未命名3.exe
Normal file
BIN
C++代码/学习/未命名3.exe
Normal file
Binary file not shown.
31
C++代码/学习/未命名6.cpp
Normal file
31
C++代码/学习/未命名6.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
int k,x, zm;
|
||||
string s,fi,w="";
|
||||
int main() {
|
||||
getline(cin,s);
|
||||
cin >> fi;
|
||||
int m=s.size();
|
||||
for(int i=0; i<m; i++) {
|
||||
s[i];
|
||||
if(isphla(s[i])){
|
||||
|
||||
}
|
||||
|
||||
if(s[i]==' '||s[i]=='.') {
|
||||
// 判断w是不是空
|
||||
if(w != "") {
|
||||
k++;
|
||||
if(w==fi) {
|
||||
cout <<k;
|
||||
return 0;
|
||||
}
|
||||
w="";
|
||||
|
||||
}
|
||||
|
||||
} else w+=s[i];
|
||||
}
|
||||
cout << zm;
|
||||
return 0;
|
||||
}
|
||||
BIN
C++代码/学习/未命名6.exe
Normal file
BIN
C++代码/学习/未命名6.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user