补全9月11日至13日课评:为13名学生创建请假文档,为5个班级创建总结文档
This commit is contained in:
36
C++代码/CSP04/01/小杨有序去重.cpp
Normal file
36
C++代码/CSP04/01/小杨有序去重.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 100010;
|
||||
int n;
|
||||
int arr[MAXN];
|
||||
|
||||
int main(){
|
||||
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++){
|
||||
cin >> arr[i];
|
||||
}
|
||||
|
||||
if(n == 0){
|
||||
cout << endl << 0 << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int j = 1; // 慢指针
|
||||
for(int i = 2; i <= n; i++){
|
||||
// i表示快指针,一直向后移动
|
||||
if(arr[i] == arr[j]) continue;
|
||||
// 如果不相同
|
||||
arr[j+1] = arr[i];
|
||||
j++;
|
||||
}
|
||||
|
||||
for(int i = 1; i <= j; i++){
|
||||
cout << arr[i] << " ";
|
||||
}
|
||||
cout << endl << j;
|
||||
return 0;
|
||||
}
|
||||
|
||||
44
C++代码/CSP04/01/小杨的回文串.cpp
Normal file
44
C++代码/CSP04/01/小杨的回文串.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s;
|
||||
int cnt1, cnt2; // cnt1大写 cnt2小写
|
||||
|
||||
int main(){
|
||||
cin >> s;
|
||||
|
||||
int len = s.size();
|
||||
for(int i = 0; i < len; i++){
|
||||
// 先数小写的个数
|
||||
if(islower(s[i])){
|
||||
cnt2++;
|
||||
}
|
||||
// 再数大写的个数
|
||||
if(isupper(s[i])){
|
||||
cnt1++;
|
||||
// 转换成小写
|
||||
s[i] = s[i] + 32;
|
||||
}
|
||||
}
|
||||
|
||||
int l = 0, r = len - 1;
|
||||
bool ok = true;
|
||||
while(l <= r){
|
||||
if(s[l] != s[r]){
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
l++, r--;
|
||||
}
|
||||
|
||||
if(ok){
|
||||
cout << "Yes";
|
||||
} else {
|
||||
cout << "No";
|
||||
}
|
||||
|
||||
cout << endl << cnt1 << endl << cnt2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
40
C++代码/CSP04/01/小杨的幸运数字.cpp
Normal file
40
C++代码/CSP04/01/小杨的幸运数字.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int n, num, cnt = 0, sum = 0;
|
||||
string str = "01";
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
|
||||
for(int i = 1; i <= n; i++) {
|
||||
cin >> num;
|
||||
int t = num;
|
||||
|
||||
string out = "";
|
||||
int cnt1 = 0;// 判断1的个数
|
||||
|
||||
while(t > 0) {
|
||||
int g = t % 2;
|
||||
|
||||
if(g == 1){
|
||||
sum++; // 总数加一
|
||||
cnt1++; // 个数加一
|
||||
}
|
||||
|
||||
out = str[g] + out;
|
||||
t /= 2;
|
||||
}
|
||||
|
||||
if(cnt1 == 1){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << cnt << endl << sum;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
C++代码/CSP04/01/小杨的报数游戏.cpp
Normal file
31
C++代码/CSP04/01/小杨的报数游戏.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
int arr[110] = {0}; // 0表示当前这个同学还在,1表示这个同学出列了
|
||||
int idx = 1; // 表示当前这个叫到第几个同学
|
||||
int cnt = 0; // 本轮报数的计数器
|
||||
int p = n; // 当前人数
|
||||
|
||||
while(p != 0){
|
||||
// 先判断当前这个人是不是出列了
|
||||
if(arr[idx] == 0){
|
||||
cnt++;
|
||||
if(cnt == k){
|
||||
// 这个人出列
|
||||
cout << idx << " "; // 当前这个人出列
|
||||
arr[idx] = 1; // 修改当前这个人出列状态
|
||||
p--;
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
if(idx > n){
|
||||
idx = 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
37
C++代码/CSP04/01/小杨的进制数位.cpp
Normal file
37
C++代码/CSP04/01/小杨的进制数位.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
int num, k;
|
||||
string out;
|
||||
string S = "0123456789ABCDEF";
|
||||
int cnt1 = 0,cnt2 = 0;
|
||||
|
||||
int main(){
|
||||
cin >> num >> k;
|
||||
|
||||
if(num == 0){
|
||||
cout << 0 << endl << 1 << endl << 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int t = num;
|
||||
while(t > 0){
|
||||
int g = t % k;
|
||||
|
||||
out = S[g] + out;
|
||||
|
||||
t /= k;
|
||||
}
|
||||
|
||||
for(char c : out){
|
||||
if(isupper(c)){
|
||||
cnt2++;
|
||||
}else if(isdigit(c)){
|
||||
cnt1++;
|
||||
}
|
||||
}
|
||||
cout << out << endl << cnt1 << endl << cnt2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user