提交 62a6d2c6 编写于 作者: 每日一练社区's avatar 每日一练社区

update dailycode pipline

上级 01430978
{
"node_id": "dailycode-659113f1c9534393bc7af45277e231c3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "23fbcc5cba90414cbd9c7d9fd09d828b",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 存了多少零钱
<p style="margin-left:.0001pt; margin-right:0">小林和小树兄弟俩相约存零钱。眼看到年底了&#xff0c;兄弟俩决定算算一共存了多少钱&#xff0c;请帮他们算出来。</p><p style="margin-left:.0001pt; margin-right:0">输入&#xff1a;</p><p style="margin-left:.0001pt; margin-right:0">两行&#xff0c;第一行三个整数分别对应元、角、分&#xff0c;表示小林存的零钱数&#xff1b;</p><p style="margin-left:.0001pt; margin-right:0">第二行三个整数分别对应元、角、分&#xff0c;表示小树存的零钱数。</p><p style="margin-left:.0001pt; margin-right:0">输出&#xff1a;</p><p style="margin-left:.0001pt; margin-right:0">两人存的钱数&#xff08;单位&#xff1a;&#xff0c;保留2位小数)</p><p style="margin-left:.0001pt; margin-right:0">样例输入&#xff1a;</p><p style="margin-left:.0001pt; margin-right:0">30 5 5</p><p style="margin-left:.0001pt; margin-right:0">45 7 4</p><p style="margin-left:.0001pt; margin-right:0">样例输出&#xff1a;</p><p style="margin-left:.0001pt; margin-right:0">76.29</p>
## template
```cpp
#include <stdio.h>
int main()
{
int y1,j1,f1,y2,j2,f2;
int y,j,f;
int shiftj = 0;
int shifty = 0;
float ss ;
scanf("%d %d %d",&y1,&j1,&f1);
scanf("%d %d %d",&y2,&j2,&f2);
f = f1 + f2;
if(f>=10)
{
f = f-10;
shiftj = 1;
}
j = j1 + j2 + shiftj;
if(j >= 10)
{
j = j - 10;
shifty = 1;
}
y = y1 + y2 + shifty;
ss = y + j/10.0 + f/100.0;
printf("%.2f\n",ss);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-8473ba565595414287199b6bf6e99650",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "48a2299546e240d8bb63d91b011b172a",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 工龄问题求解,工龄 人数
<p>给定公司N名员工的工龄&#xff0c;要求按工龄增序输出每个工龄段有多少员工。输入首先给出正整数N&#xff0c;即员工总人数&#xff1b;
随后给出N个整数&#xff0c;即每个员工的工龄&#xff0c;范围在[0, 99]。其中&#xff0c;0-9为第1个工龄段&#xff0c;10-19为第2个工龄段&#xff0c;&#xff0c;90-99为第10个工龄段。按工龄的递增顺序输出每个工龄的员工个数&#xff0c;格式为&#xff1a;“工龄:人数”。每项占一行。如果人数为0则不输出该项。</p>
## template
```cpp
#include <stdio.h>
int main()
{
int i,n,a[11]= {0},x;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&x);
if(x<=9)
a[1]++;
else if(x>9&&x<=19)
a[2]++;
else if(x>19&&x<=29)
a[3]++;
else if(x>29&&x<=39)
a[4]++;
else if(x>39&&x<=49)
a[5]++;
else if(x>49&&x<=59)
a[6]++;
else if(x>59&&x<=69)
a[7]++;
else if(x>69&&x<=79)
a[8]++;
else if(x>79&&x<=89)
a[9]++;
else
a[10]++;
}
for(i=1;i<=10;i++){
if(a[i]>0){
printf("%d-%d:%d\n",i*10-10,i*10-1,a[i]);
}
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-9b98838d461840a68d81fa582efcc5d0",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "b76b09bcf1264b0191d968f66d7f8e64",
"keywords": "算法初阶,基础知识,特征序列,概率分析和随机算法,概率分析和指示器随机变量的进一步使用"
}
\ No newline at end of file
# 求分数数列的前N项和
有一分数序列:2/1,-3/2,5/3,-8/5,13/8,-21/13,…, 由用户输入项目数N,求这个数列的前N 项之和
## template
```cpp
#include<stdlib.h>
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int i;
double a1 = 2, b1 = 1;
double a2 = 3, b2 = 2;
double sum = a1/b1 - a2/b2;
if(n==1) printf("%f\n",a1/b1);
else if (n==2) printf("%f\n",sum);
else{
for(i = 0;i<n-2;i++){
double exp = a2 / b2;
if(i%2==0) exp *= -1;
sum += exp;
double a = a1 + a2;
double b = b1 + b2;
a1 = a2;b1 = b2;
a2 = a; b2 = b;
}
printf("%f\n",sum);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b0c9775cbc6d4ef28d69b8fdab3f0378",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "42ff182f3527447da5feb913a15ca2d0",
"keywords": "算法,图形输出"
}
\ No newline at end of file
# 输入一个正整数n(代表图形的行数),输出如样例形式的图形。
输入:7
输出:
D D
CD DC
BCD DCB
ABCDDCBA
BCD DCB
CD DC
D D
## template
```cpp
#include<stdio.h>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n;
cin>>n;
vector<string> a(n,""),b(n,"");
int m=(n+1)/2;
int p=0;
for(int i=m-1;i>=0;i--){
for(int j=0;j<=i;j++)
a[i].push_back('A'+j+p);
b[i]=a[i];
reverse(b[i].begin(),b[i].end());
for(int j=i+1;j<m;j++){
a[i]+=" ";
b[i]+=" ";
}
p++;
}
p=0;
for(int i=n-1;i>=m;i--){
a[i]=a[p];
b[i]=b[p++];
}
for(int i=0;i<n;i++)
cout<<a[i]<<b[i]<<endl;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-d0584ef2dfdc41d799d69522c0b52e3f",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f6bbde31ecf143c18180309f822dd46f",
"keywords": "算法中阶,动态规划,最长公共子序列,高级设计和分析技术"
}
\ No newline at end of file
# 数组元素循环右移问题
题目:一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?
输入格式:
每个输入包含一个测试用例,第1行输入N(1≤N≤100)和M(≥0);第2行输入N个整数,之间用空格分隔。
输出格式:
在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。
输入样例:
6 2
1 2 3 4 5 6
输出样例:
5 6 1 2 3 4
## template
```cpp
#include<stdio.h>
int main()
{
int n,m,a[1000];
scanf("%d %d",&n,&m);
m = m % n;
int count=m;
while(m<n)
{
scanf("%d",&a[m]);
m++;
}
for(int i=0;i<count;i++)
scanf("%d",&a[i]);
int first=1;
for(int i=0;i<n;i++)
{
if(!first)printf(" ");
printf("%d",a[i]);
first=0;
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b7369ca7ec414d56af56ba02b0a69c75",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "81b094ea77f744eeb7b681e1d5fae331",
"keywords": "算法初阶,基础知识,分治策略,证明主定理,对b的幂证明主定理"
}
\ No newline at end of file
# 编写程序:判断素数的个数
<p>在一个数组A中存放100个数据&#xff0c;用子函数判断该数组中哪些是素数&#xff0c;并统计该素数的个数&#xff0c;在主函数中输出该素数的个数</p>
## template
```cpp
#include <stdio.h>
#include <stdlib.h>
int isPrime(int n)
{
int i = 2;
if(n<2) return 0;
for (i=2;i<n;i++)
{
if(n%i == 0)
return 0;
}
return 1;
}
int CountPrime(int a[],int size)
{
int i =0,count = 0;
for (i = 0;i<size;i++)
{
if(isPrime(a[i]))
{
printf("%d ",a[i]);
count++;
if(count%10 == 0)
printf("\n");
}
}
printf("\n");
return count;
}
int main()
{
int a[100],i,count = 0;
for(i = 0;i<100;i++)
a[i] = rand()%1000;
printf("素数的个数:%d\n",CountPrime(a,100));
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-09803f06a26b40b1acc71cb81904ca38",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "bcc8e5e7bdee4384acf884f7a2917198",
"keywords": "数学运算"
}
\ No newline at end of file
# 商品优惠计算器
<p>商品优惠计算器
使用if语句编程实现输入购货金额&#xff0c;输出实际付款金额。购货折扣率如下&#xff1a;
购货金额≤500元 不打折
500元&lt;购货金额≤1000元 9折
1000元&lt;购货金额 8折</p>
## template
```cpp
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
{
float money=0.0;
float pay=0.0;
bool run = true;
while(run)
{
printf("\n请输入购货金额:\n");
scanf("%f", &money);
if(money >1000)
{
pay=money*0.8;
printf("打八折,应付金额:%.2f\n",pay);
}
else if((money >500)&&(money <=1000))
{
pay=money*0.9;
printf("打九折,应付金额:%.2f\n",pay);
}
else if(money <=500)
{
printf("不打折,应付金额:%.2f\n",money);
}
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b452064dae7f49daa4287d2d1d8be8c8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "64397c58dd764b28a69ae59cb1741686",
"keywords": "算法高阶,数论算法,元素的幂,算法问题选编"
}
\ No newline at end of file
# 移动数组中的元素
题目描述
将一维数组中的元素循环左移 k 个位置
输入描述
第 1 行是一维数组元素的个数 n (数组大小)
第 2 行是一个整数 k , 表示移动的位置
下面 n 行为数组的元素个数
输出描述
输出 n 行,表示移动后的数字
## template
```cpp
#include<stdio.h>
#define N 10000
int main()
{
int k,a[N],b[N],n,t,w,i;
scanf("%d",&n);
scanf("%d",&k);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for (i = 0; i < k % n; i++)
b[i] = a[i];
for (i = 0; i < n; i++)
{
if (i < n - k % n)
a[i] = a[i + k % n];
else
a[i] = b[i - n + k % n];
}
for(i=0;i<n;i++)
printf("%d\n",a[i]);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-fe83f29c5d744a0d92ed241ffa819776",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "70771cfc0f8446f89d858067d0f83ebd",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量,期望为线性时间的选择算法"
}
\ No newline at end of file
# 个位数是6,且能被3整除的五位数共有多少个?
<p>要求:
1、必须包含循环结构、顺序结构、选择分支结构。
2、必须包含数组
3、必须包含一个以上函数
4、可以包含方针</p>
## template
```cpp
#include <iostream>
using namespace std;
void search1(){
int i,t=0;
for(i=10000;i<=99999;i++){
if(i%3==0&&i%10==6)
t++;
}
cout<<t;
}
int main()
{
search1();
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-f755126bfaad4e12b83f1f14df1297ba",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "0464585875d748ef8c78db07d22ba5da",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 一个整数的序列,要求对其重新排序
<p>一个整数的序列&#xff0c;要求对其重新排序。排序要求:
1.奇数在前&#xff0c;偶数在后&#xff1b;
2.奇数按从大到小排序&#xff1b;
3.偶数按从小到大排序。<br />
输入一行&#xff0c;包含整数个数n&#xff0c; n个整数值&#xff0c;彼此以一个空格分开。
按照要求排序后输出一行&#xff0c;包含排序后的n 个整数。
 </p>
## template
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a, int b){
    int x = a % 2;
    int y = b % 2;
    if(x == y)
        if(x == 0)
            return a < b;
        else
            return a > b;
    else
        return x > y;
}
int main()
{
    int n, i;
    cin >> n;
    int a[n];
    for(i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n, cmp);
    for(i = 0; i < n; i++)
        cout << a[i] << " ";
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4d4a1d972a6e474194d4d8408400a210",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "369886bd0cc34c37add5a3bd8c372056",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 给出一个由O和X组成的串,长度为1~80,统计得分
给出一个由O和X组成的串,长度为1~80,统计得分,每个O的得分为目前连续出现的O的个数,X的得分为0,例如OOXXO的得分为1+2+0+0+1.
## template
```cpp
#include"stdlib.h"
#include"string.h"
#include"stdio.h"
int main()
{
char s[85];
int score = 0,x;
scanf("%s",&s);
for (int i = 0;s[i];i++)
{
if (s[i] == 'X')
score += 0;
if (s[i] == 'O')
{
int temp = 1;
if (i == 0)score += 1;
else
{
x=i;
while (x > 0)
{
if (s[x - 1] == 'O')temp++;
else break;
x--;
}
score += temp;
}
}
}
printf("%d\n", score);
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a905ce2f8a314d7b9f001b91ec96e70c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "586adba1cd25495db0b4047bcdebe834",
"keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法"
}
\ No newline at end of file
# 一个班有10个同学,通过键盘输入成绩,并打印输出,每行输出5个同学的成绩。并求出平均成绩,最高分、最低分并输出。
<p>一个班有10个同学&#xff0c;通过键盘输入成绩&#xff0c;
并打印输出&#xff0c;每行输出5个同学的成绩。并求出平均成绩&#xff0c;最高分、最低分并输出。算法分析&#xff1a;
(1)定义一个数组用来存放10个成绩数据。
(2)用循环结构实现成绩输入&#xff1b;
(3)用循环结构实现成绩输出,并控制换行&#xff1b;
(4)使用循环结构求平均成绩、最高分、最低分并输出。</p>
## template
```cpp
#include <stdio.h>
int main(){
int x,i,max=0,min=0;
double sum=0,ave=0;
int a[10];
for(i=0;i<10;i++){
scanf("%d",&a[i]);
if(i==0)
min = a[i];
sum+=a[i];
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
ave=sum/10;
for(i=0;i<5;i++)
printf("%d ",a[i]);
printf("\n");
for(i=5;i<10;i++)
printf("%d ",a[i]);
printf("平均成绩%f,最高分%d,最低分%d ",ave,max,min);
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-5540e08dda46435695d0a4b2859d8c4a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ea9715e1ed5c4f79bf050f6747f60a60",
"keywords": "算法高阶,计算几何学,算法问题选编,确定任意一对线段是否相交"
}
\ No newline at end of file
# 实现五则运算
<pre><p>设计一个可以完成任意五则运算&#xff08;加法/减法/乘法/除法/取余&#xff09;的程序。除法按照计算机中<strong>整型相除</strong>来计算。
输入格式
多行输入&#xff0c;每输入一行数据对应输出一行。
每行输入格式为 a # b&#xff0c;其中 &#xff03;∈{&#43;,−,∗,/,%}
a,b均为自然数
输出格式
每行输出对应的计算结果&#xff1b;
当运算为除法/取余的时候&#xff0c;如果除数为 0 &#xff0c;输出 <code>WA</code> 。</pre>
<p>输入样例</p>
<pre>
<code>2&#43;2
4*5
6/7
4%3
4%0</code></pre>
<p>输出样例</p>
<pre>
<code>4
20
0
1
WA</code></pre>
## template
```cpp
#include<stdio.h>
int main()
{
int a;
int b;
char operation;
int num;
while (scanf("%d", &a) != EOF)
{
scanf("%c", &operation);
scanf("%d", &b);
if (operation == '+')
{
num = a + b;
printf("%d\n", num);
}
else if (operation == '-') {
num = a - b;
printf("%d\n", num);
}
else if (operation == '*') {
num = a * b;
printf("%d\n", num);
}
else if (operation == '/' && b != 0) {
num = a / b;
printf("%d\n", num);
}
else {
printf("%s\n", "WA");
}
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-ab2faaa788af4af68e393c3ef352f3b8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "b808c6775b7447a8956e6ee05fd004c2",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 输入两个小写英语字母后, 输出两个字母的差
两个小写字母的差用整数输出。
但是,输入小写以外的文字就结束程序。
比较两个字母的部分用diff这个名字的函数书写。执行结果
请输入两个小写:a b
字母a和字母b的区别是1。
请输入两个小写:f b
字母f和字母b的差异是4。
请输入两个小写:0 a
退出程序。
## template
```cpp
#include <iostream>
using namespace std;
int diff(char ch1, char ch2)
{
if (ch1 > ch2) return ch1 - ch2; else return ch2 - ch1;
}
int main()
{
char a, b;
while (1)
{
cout << "请输入两个小写:";
cin >> a >> b;
if (a > 'z' || a < 'a' || b > 'z' || b < 'a') break;
cout << "文字" << a << "和文字" << b << "的差异是" << diff(a, b) << "。\n";
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-61b527860365443e99313e78c5f585f8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d2a79e8dde294e36945f538f21b48531",
"keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量"
}
\ No newline at end of file
# 排序
试题描述
由键盘上输入n个整数,请将这些数从大到小排序,然后输出排序后的数列。
输入
输入包含两行:
第一行是n(1 <= n <= 1000)。
第二行是n个整数,邻近两数之间用一个空格隔开。
输出
输出排序后的n个整数,邻近两数之间用一个空格隔开。
输入示例
5
8 2 5 1 2
输出示例
8 5 2 2 1
数据范围
输入和输出均为int范围的整数
## template
```cpp
#include<iostream>
using namespace std;
int main() {
int n,tmp;
cin >> n;
int *a = new int[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] < a[j]) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
for (int i = 0; i < n; i++) {
cout << a[i];
if (i != n - 1)
cout << " ";
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-26432dc3e35a406690201c8b05e7100c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "0fa88446d639403bb7c42e1e6f80a625",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 字符数组
<p>编写一个以两个字符数组作为输入的函数。
如果第二个数组包含在第一个数组中&#xff0c;则函数返回第一个数组中第二个数组开始的第一个索引。
如果第二个数组不被包含在第一个数组&#xff0c;然后函数应该return -1
输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’l’,’l’]  就 return 1.
输入 [’c’,’a’,’l’,’l’,’i’,’n’,’g’] 和 [’a’,’n’] 就 return -1.</p>
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
char a[128],b[128];
int numA, numB;
cout << "请输入第一个数组元素个数:";
cin >> numA;
cout << "请输入第一个数组元素:";
for (int i = 0; i < numA; ++i)
cin >> a[i];
cin.clear();
cin.sync();
cout << "请输入第二个数组元素个数:";
cin >> numB;
cout << "请输入第二个数组元素:";
for (int i = 0; i < numB; ++i)
cin >> b[i];
int num = 0;
string index;
for (int j = 0; j < numB; j++)
{
for (int k = 0; k < numA; k++)
{
if (b[j] == a[k])
{
index += to_string(k);
num++;
break;
}
}
}
if (num == numB)
{
cout << "第二个数组包含在第一个数组中" << endl;
cout << "第一个数组中第二个数组开始的第一个索引为:" << index.substr(0,1) << endl;
}
else
cout << "第二个数组不被包含在第一个数组";
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-02314c22b3ea40f087778df8be331d2b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "36cfcc0e855e4cde8449cfb24e471727",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 从键盘输入任意一个大写英文字母,要求它在26个字母表中的位置和其后面的第四个字母
例如:程序运行
输入:B<回车>
输出:B在第2个位置,其后面第四个字母是F
## template
```cpp
#include <stdio.h>
int main(){
char c,c2;
printf("输入:");
c = getchar();
int m=0,n=0;
if(c>='A'&& c<='z')
{
m = c - 'A' + 1;
if(m < 23)
{
c2 = c + 4;
n = m+4;
}
}
if(n > 0)
printf("%c在第%d个位置,其后面第四个字母是%c\n",c,m,c2);
else
printf("%c在第%d个位置,其后面没有第四个字母\n",c,m);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-06a0e922ceb94cba842194a19fb710fb",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "8d3e31bef80c485bb204d08d7c532243",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 按要求排序数组
<p>&nbsp;给你一个整数数组 arr 。请你将数组中的元素按照其二进制表示中,数字 1 的数目升序排序。 如果存在多个数字二进制中 1 的数目相同,则必须将它们按照数值大小升序排列。请你返回排序后的数组。</p>
## template
```cpp
#include<stdio.h>
#include<stdlib.h>
int oneNum(int x)
{
int cnt = 0;
while(x)
{
cnt++;
x = x&(x-1);
}
return cnt;
}
int cmp(const void *a,const void*b)
{
int al,bl;
int ret;
al = *(int*)a;
bl = *(int*)b;
ret = oneNum(al) - oneNum(bl);
return ret ? ret : al - bl;
}
int main()
{
int s[]={1,2,3,5,6,7,8},i;
int len = sizeof(s)/sizeof(*s);
qsort(s,len,4,cmp);
for(i = 0 ; i < len ; i++)
{
printf("%d\n",s[i]);
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-e22aa7f4699344e38010b961b7e90b0b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3a364cdce27b488087d0b038da23f998",
"keywords": "数学,算法"
}
\ No newline at end of file
# 检查一个3位数是否是水仙花数
检查一个3位数是否是水仙花数。
输入:一个数字,比如 371,输出:x是水仙花数,
如果不是,则输出:x不是水仙花数。
注:x为输入的数字
## template
```cpp
#include <iostream>
using namespace std;
int main()
{
int a, b, c, y, n = 0;
cout << "请输入三位数字:" << endl;
cin >> n;
a = n % 1000 / 100;
b = n % 100 / 10;
c = n % 10 / 1;
y = a*a*a + b*b*b + c*c*c;
if (y == n) cout << n << "是水仙花数" << endl;
else cout << n << "不是水仙花数" << endl;
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-7a9f91f6fb5a4479bb5059429e910d8c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "253efcfc76d543c9911d2fd0e022e23f",
"keywords": "时间转换"
}
\ No newline at end of file
# 秒数转换
输入一个秒数,转换成HH:MM:SS的格式输出。
输入样例
365
输出样例
00:06:05
## template
```cpp
#include<cstdio>
int n;
void print(int x){
if(x==0)printf("00");
else if(x<10)printf("0%d",x);
else printf("%d",x);
return;
}
int main(){
scanf("%d",&n);
int s,f,m;
s=n/3600;
f=n/60%60;
m=n%60;
print(s);
printf(":");
print(f);
printf(":");
print(m);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-927c05f4f0cc498d87f5240bb69013b1",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f6a830097bd34ae2b32cb1015a9fbad2",
"keywords": "算法,字符串"
}
\ No newline at end of file
# 找出string中只出现过一次的字符
找出string中只出现过一次的字符
例如"abcdef abcd"中需要得到ef
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string temp = "";
    cout << "请输入字符串:";
    cin >> temp;
    string str = "";        
    string str1 = "";        
    for (int i = 0; i < temp.length(); i++)
    {
        string tempSub = temp.substr(i, 1);    
        int b = temp.rfind(tempSub);                
        if (i == b && str1.find(tempSub) == -1)        
            str +=temp.substr(i, 1);
        else if (str1.find(tempSub) == -1)
            str1 += temp.substr(i, 1);
    }
    cout << "只出现一次的字符:" << str << endl;
    cout << "重复出现的字符的字符:" << str1 << endl;
    system("pause");
    return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-16d8bf9ca858422293cab4a63d11d0ee",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "a0660c1ff1b349b6a58503a3b6c99dbf",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 找出小于平均值的数。
<p>从键盘输入一个正整数存入变量n中&#xff0c;再输入n个整数&#xff0c;然后找出所有小于平均值的数&#xff0c;并按输入顺序输出。
 
 </p>
## template
```cpp
#include<stdio.h>
int main()
{
int i,n,sum=0,a[100];
float ave;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
ave=sum*1.0/n;
for(i=0;i<n;i++){
if(a[i]<ave)
printf("%d",a[i]);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-31b232fe873646698ccfde07ef62a2df",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ccd00d8423b44763960adb0cd515538e",
"keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术"
}
\ No newline at end of file
# 水果计费系统
<p>本关任务&#xff1a;编写程序&#xff0c;有五种水果&#xff0c;apple、banana、orage、strawberry、pear&#xff0c;每一种有一个价格&#xff08;浮点小数&#xff09;&#xff0c;由老板输入&#xff0c;请提示用户选择什么水果&#xff0c;购买数量&#xff08;按照斤两&#xff09;&#xff0c;然后将总价显示出来。</p>
## template
```cpp
#include<stdio.h>
int main(){
typedef enum {apple, banana, orange, strawberry, pear} fruits;
double prices[5];
fruits purchase;
int fruit;
double amount;
for(int i = 0; i < 5; i++)
scanf("%lf", &prices[i]);
printf("水果编号:1.苹果 2.香蕉 3.橘子 4.草莓 5.梨\n");
printf("请输入购买的水果(1~5),以及购买数量(按照斤两):\n");
scanf("%d %lf", &fruit, &amount);
purchase = (fruits)fruit;
printf("总价为:%.3lf", prices[purchase-1]*amount);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-22df2bc3bccc4c0aacf00251b43bb2bd",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "0e25906f699240c19576a92aff9f37ef",
"keywords": "数列,递归,数学运算"
}
\ No newline at end of file
# 用递归求第n项的值
1,2,4,2,3,6,12,6,3,....求第n项值
## template
```cpp
#include <stdio.h>
int fun(int n,int *x,int *y)
{
int sum = 0,i;
int size = 0;
int dd = 1;
for (i = 1; i <= (*x);i++)
{
sum += (2*i-1);
}
if (sum == n)
{
*y = 2*(*x) -1;
return (*x);
}else if (sum > n)
{
(*y) = n - (sum - (2 * (*x) -1));
size = 2* (*x) -1;
dd = (*x);
for (i = 2; i <= (*y);i++)
{
if(i <= (*x))
dd *= 2;
else
dd /= 2;
}
return dd;
}else
{
(*x)++;
return fun(n,x,y);
}
}
int main()
{
int n;
int row = 1,col = 0;
int val;
row = 1;
col = 0;
printf("请输入n:");
scanf("%d",&n);
val = fun(n,&row,&col);
printf("第%d项是:%d\n",n,val);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-83b2c25568134ccab795b09d81b135f9",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9eed791912c84c80b4b83bf3e51d03a1",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 计算字符串逆序数
例如:字符串中的内容为:a1Ab1D2,1<A,A<b 1<D 则调用该函数后,返回码为:3。 
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
int solve(string s)
{
if (s.length() == 0) return 0;
int n = 0;
for (int i = 1; i < s.length(); i++)
if (s.c_str()[i] < s.c_str()[i - 1]) n++;
return n;
}
int main()
{
string s = "a1Ab1D2";
int n = solve(s);
cout << n << endl;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4e3b4cff80674a318a229cd5c8791b2a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "91c323f9f15544c3b2cba964610b8587",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# if else 和 switch 使用
<p>输入学生成绩&#xff0c;
若成绩在95分以上&#xff0c;输出“A”&#xff1b;
若成绩在85~94分&#xff0c;输出“B”&#xff1b;
若成绩在75~84分&#xff0c;输出“C”&#xff1b;
若成绩在65~74分&#xff0c;输出“D”&#xff1b;
若成绩在65分以下&#xff0c;输出“E”。&#xff08;分别用if else 和 switch 语句完成&#xff09;</p>
## template
```cpp
#include "stdio.h"
int main(){
int score;
scanf("%d",&score);
if(score>=95){
printf("A\n");
}else if(score>=85 && score<=94){
printf("B\n");
}else if(score>=75 && score<=84){
printf("C\n");
}else if(score>=65 && score<=74){
printf("D\n");
}else{
printf("E\n");
}
printf("以下用switch语句实现相同功能\n");
score = score-5;
score = score/10;
switch(score){
case 9:
printf("A\n");
break;
case 8:
printf("B");
break;
case 7:
printf("C\n");
break;
case 6:
printf("D\n");
break;
default:
printf("E\n");
break;
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-db39972a67974a50b6b28e5faa129aa6",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9e6bc51acdf44c64ae58d8891c769c0b",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 将字符串2小写字母复制到字符串1
<p>编写程序,输入字符串s2,将其中所有小写字母复制到字符串数组strl中。例如<br />
aal1bb22cc33de4AA55BB”,生成的strl为&#34;aabbccde&#34;</p>
## template
```cpp
#include<stdio.h>
int main()
{
int sum=0,t=0,i;
char s[50],s1[50];
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]>='a'&&s[i]<='z'){
s1[t++]=s[i];
}
}
s1[t]='\0';
printf("%s",s1);
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-18fc61b230304d109c0a47245b2c9aa0",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d73526e1aaf443009e8ed3a3201d823d",
"keywords": "递归,算法"
}
\ No newline at end of file
# 编写递归函数和非递归函数
<p>编写一个递归函数和一个非递归函数&#xff0c;分别实现求1&#43;2&#43;3&#43;...&#43;n</p>
## template
```cpp
#include <stdio.h>
int sum(int n)
{
if(n == 1)
return 1;
else
return n + sum(n-1);
}
int sum_2(int n)
{
int ss = 0;
for (int i = 1; i <=n;i++)
{
ss += i;
}
return ss;
}
int main()
{
int n;
printf("请输入n:");
scanf("%d",&n);
if(n == 0)
{
printf("请输入正整数n");
return -1;
}
int s1 = sum(n);
int s2 = sum_2(n);
printf("递归计算=%d;循环计算=%d\n",s1,s2);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-70a39eaf8f054d33b89aad6f5f3fb871",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "15ca2c332f8747dd9dcaa802ecde5b44",
"keywords": "数列,数学运算"
}
\ No newline at end of file
# 求数列第n项值
<p>求数列第n项值&#xff1a;1,2,3,6,11,20,37,68,125,230,.....例如:第7项为37&#xff0c;第9项为125。</p>
## template
```cpp
#include <stdio.h>
int main(void) {
int n;
printf("请输入n的值:");
scanf("%d",&n);
if(n==1){
printf("第1项为1\n");
}else if(n==2){
printf("第2项为2\n");
}else if(n==3){
printf("第3项为3\n");
}else{
int f1=1,f2=2,f3=3;
int i,fn;
for(i=4;i<=n;i++){
fn=f1+f2+f3;
f1=f2;
f2=f3;
f3=fn;
}
printf("第%d项为%d\n",n,fn);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-8b7bc583ff9c423f9a3a5e2f768984ea",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "455e33582b8745ab8f41fc09e6adad82",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 找出字符串中出现最多的字母
Description
钟Sir是一个迷信的(superstitious)家伙。他相信每一个字符串(string)里都有一个幸运字符。我们可以通过以下方法找到这个字符。例如,在字符串abbccc中,c 出现的次数最多,所以这个幸运字符就是 c 啦!(>_<)  (钟Sir的想法好简单啊…)
Input
第一行是测试数据的组数n,接下来的每组测试数据占一行,每行数据不超过1000个字符且非空。
字符串里只含小写字母。
Output
每组数据对应输出一行,包括出现次数最多的字符和该字符出现的次数,中间是一个空格。如果有多个字符出现的次数相同且最多,那么输出ASCII码最小的那一个字符。
Sample Input
2
abbccc
adfadffasdf
Sample Output
c 3
f 4
## template
```cpp
#include <string.h>
#include"stdio.h"
int main(void)
{
int n,i, z[26], max, xia;
char c[1050], ch;
scanf("%d",&n);
while(n>0)
{
n--;
scanf("%s", c);
for(i=0; i<26; i++)
z[i]=0;
xia=strlen(c);
for(i=0; i<xia; i++)
z[c[i]-'a']++;
max=z[0]; xia=0;
for(i=1; i<=25; i++)
if(z[i]>max){
max=z[i];
xia=i;
}
ch='a'+xia;
printf("%c %d\n", ch, max);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-70b1adc8c0834314ae6fbf51477e95e3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9f7f3dcf9c4c437fb1d6a5348f308453",
"keywords": "循环"
}
\ No newline at end of file
# 不同方式求n的阶乘
<p>求n的阶乘&#xff08;用三种不同的循环实现&#xff0c;提示&#xff1a;先从键盘输入n的值&#xff09;while、do while和for</p>
## template
```cpp
#include <stdio.h>
int main(void) {
int n;
printf("请输入n的值:");
scanf("%d",&n);
int temp=n,sum=1;
while(temp>1){
sum*=temp;
temp--;
}
printf("%d的阶乘是%d\n",n,sum);
temp=n;
sum=1;
do{
sum*=temp;
temp--;
}while(temp>1);
printf("%d的阶乘是%d\n",n,sum);
temp=n;
sum=1;
for(;temp>1;temp--){
sum*=temp;;
}
printf("%d的阶乘是%d\n",n,sum);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-c72f6867061946e9968b2297a8051238",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d70ed1dbad074ec3afbd48f64094dc75",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 字符串的处理
<p>给定一个正整数N和一个由小写英文字母组成的长度N的字符串S。确定该字符串是否是某个字符串的两个副本的连接。也就是说&#xff0c;确定是否存在一个字符串T使S&#61;T&#43;T。如果S是某个字符串的两个副本的连接&#xff0c;则输出Yes;否则,直接输出No。
例如&#xff0c;输入6&#xff08;回车&#xff09;abcabc&#xff0c;输出Yes&#xff08;回车&#xff09;Let T&#61;abc&#xff0c;and S&#61;T&#43;T。
或者输入4&#xff08;回车&#xff09;abac&#xff0c;输出No&#xff08;回车&#xff09;结束。</p>
## template
```cpp
#include <stdio.h>
int main() {
int len,i,judge=0;
scanf("%d", &len);
char a[len+1];
scanf("%s", a);
if(len%2==0) {
for(i=0;i<(len/2);i++)
if(a[i]!=a[(len/2)+i]){
judge=1;
break;
}
if(judge==1)
printf("No");
else {
printf("Yes");
}
} else
printf("No");
printf("\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-c3caf7834f9349d5b1b6a929ec8421e8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9c8ae3b302f346f09bac14759a1721bf",
"keywords": "数列"
}
\ No newline at end of file
# 怎么求尾数与常数之和?
<p>数列的前3项都为1&#xff0c;从第4项开始&#xff0c;每项都是其前3项的和&#xff1a;1, 1, 1, 3, 5, 9, 17, … 请你编程求出数列第N项的<strong>4位尾数</strong>与90000之和。输入一个正整数N&#xff0c;输出所求的和。</p>
## template
```cpp
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <set>
using namespace std;
#define NUM 10000
long long dp[1000000];
int main(){
    int n;
    cin>>n;
    dp[1]=1;
    dp[2]=1;
    dp[3]=1;
    for(int i=4;i<=n;i++){
        dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
    }
    cout<<dp[n]<<endl;
    long long x=dp[n]%NUM+90000;
    cout<<x;
    system("pause");
    return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-96f4e45c16414e43983cf3462376a1fe",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9e6f1b2e353b4e1396414bbe396667e6",
"keywords": "质数,数学运算"
}
\ No newline at end of file
# 按要求求质数
求10-100之间个位数为7的质数
## template
```cpp
#include <stdio.h>
int isp(int n)
{
int i;
if (n<2)
return 0;
for (i=2;i*i<=n;++i)
{
if (n%i==0)
return 0;
}
return 1;
}
int main()
{
int i=17;
while (i<=100)
{
if (isp(i))
printf("%d ",i);
i+=10;
}
printf("\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-8c968812d8a347ccafd27adb86751307",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4ac080abbef044509263cd541968c848",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 整数分解
<p>输入一个整数&#xff0c;将其按7进制位分解为各乘式的累加和&#xff08;下图为输出结果&#xff09;</p>
<p style="text-align:center"><img alt="" src="https://img-ask.csdnimg.cn/upload/1623209867965.jpg" />
 </p>
## template
```cpp
#include<stdio.h>
#define X 7
int main()
{
int i=0;
int mod,num=720;
while(num)
{
mod=num%X;
num/=X;
if(mod!=0)
printf("%d*7^%d%c",mod,i,(num>0)?'+':'\n');
i++;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-5e6fa35d05e049c78b70f5bbea6dd98a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "be548b4f878140bea3f9131a5041cfc3",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 按要求完成数据的输入输出
<p>有6个学生&#xff0c;每个学生的数据包括学号、姓名、3门课的成绩、平均成绩&#xff0c;输入每个学生的信息&#xff0c;平均成绩需通过计算得出&#xff0c;输出学生的信息。要求&#xff1a;输入、输出不使用函数。</p>
## template
```cpp
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n;
struct person
{
char id [20];
char name [20];
int s1,s2,s3;
int sum;
float ave;
} p[100];
int main()
{
int i,j,t,m;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
p[i].sum=0;
scanf("%s %s %d %d %d",p[i].id,p[i].name,&p[i].s1,&p[i].s2,&p[i].s3);
p[i].sum+=p[i].s1+p[i].s2+p[i].s3;
p[i].ave=p[i].sum/3.0;
}
for(i=0; i<n; i++)
{
printf("%s %s %d %d %d %.2f\n",p[i].id,p[i].name,p[i].s1,p[i].s2,p[i].s3,p[i].ave);
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b8d729509e53482a81495fb864fa18cf",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c3130cc1775e4e3dbfa8672c45e9a7f5",
"keywords": "算法高阶,矩阵运算,矩阵求逆,算法问题选编"
}
\ No newline at end of file
# 计算位于矩阵边缘的元素之和
描述
输入一个整数矩阵,计算位于矩阵边缘的元素之和。所谓矩阵边缘的元素,就是第一行和最后一行的元素以及第一列和最后一列的元素。
输入
第一行分别为矩阵的行数m和列数n(m < 100,n < 100),两者之间以一个空格分开。
接下来输入的m行数据中,每行包含n个整数,整数之间以一个空格分开。
输出
输出对应矩阵的边缘元素和
样例输入
3 3
3 4 1
3 7 1
2 0 1
样例输出
15
## template
```cpp
#include<stdio.h>
int main()
{
int a[256][256];
int n,m,i,j,sum=0;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%d",&a[i][j]);
if (i == 1 || i == n || j == 1 || j == m) sum += a[i][j];
}
}
printf("%d",sum);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-e0f8289987d842899bb2e289b016f74d",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "7e720ceb2ea34d8b90120c335ebc9c67",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 从指定位置插入字符串
编写程序,输入字符串S1和S2以及插入位置n,在字符串S1中的指定位置n处插入字符串S2。例如,输入“jiangsu”、“123”和位置3,则输出“ji123angsu”。
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1;
string str2;
int pos;
do
{
if ((cin >> str1 >> str2 >> pos) && (pos >= 1))
{
str1.insert(pos - 1, str2);
cout << str1 << endl;
}
else
{
cout << "Invalid Input" << endl;
break;
}
} while (false);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-6df0dbfb55304437ae730b8a25f689fa",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "e5f330711b214d00a540ebc8be49194c",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 字符串匹配
<p>输入两个字符串s1和s2&#xff0c;在s1中查找s2对应的字符串是否存在&#xff0c;若存在则输出它第一次出现的位置&#xff1b;若不存在&#xff0c;则输出“没有找到该字符串”。</p>
## template
```cpp
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s1, s2;
cout << "请输入第一个字符串:";
cin >> s1;
cout << "请输入第二个字符串:";
cin >> s2;
if (s1.find(s2) != -1)
cout << s1.find(s2)<<endl;
else
cout << "没有找到该字符串"<<endl;
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b2ddcea7fd7c4031b3fa912a131f05f1",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ca93a2582fff4a55a5654e1185e27def",
"keywords": "区间树,算法中阶,数据结构,数据结构的扩张"
}
\ No newline at end of file
# 由数值大小在闭区间的
<p>创建一个大小为 100 的整型数组&#xff0c;数组元素由数值大小在闭区间[0,1000]内的
随机数组成。在控制台窗口中输出数组内数值为 7 的倍数&#xff0c;且除以 3 余数为 2 的
元素。若数组中不存在符合规则的元素&#xff0c;则在控制台中给出相应提示</p>
## template
```cpp
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[100];
int i,nmb = 0;
for(i = 0;i<100;i++)
a[i] = rand()%1001;
for (i = 0;i<100;i++)
{
if( (a[i]%7 == 0) && (a[i]%3 ==2) )
{
printf("%5d",a[i]);
nmb++;
}
}
printf("\n");
if(nmb == 0)
printf("没有符合条件的数\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-5d77182582744a6399fc77fdf3bea6fd",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "0d9c1d0b6ee2430b80ed3f209f363eaa",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# 找出所有三位素数
题目描述
一个n位超级素数是指一个n位正整数,它的前1位,前2位,......,前n位均为素数,例如,733是个3位超级素数,因为7,73,733均为素数。输出全部的3位数超级素数。
输入
输出
全部的3位数超级素数,每行一个数
## template
```cpp
#include <stdio.h>
int isprime(int x)
{
if (x == 0 || x == 1) return 0;
for (int i = 2; i <= x / 2; i++)
if (!(x % i)) return 0;
return 1;
}
int isallprime(int x)
{
do
{
if (!isprime(x)) return 0;
x /= 10;
}
while (x > 0);
return 1;
}
int main()
{
for (int i = 111; i <= 1000; i++)
if (isallprime(i)) printf("%d\n", i);
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-bbb857583f8042f985666572334c29be",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "98de8d7af3e447b2ac5660b209dfe5dc",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 数学题
编程求1-200中能被2、3、5除余1的前10个整数。
## template
```cpp
#include <stdio.h>
int main()
{
int n=0,i;
for(i=1; i<=200; i++)
{
if((i%2==1)&&(i%3==1)&&(i%5==1))
{
n++;
if(n<=10)
printf("%d ",i);
if(n==10)
break;
}
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-0462cfda310f4e78bae1e1b004c81875",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "bbcd71f202e843ac852d3a3523b1a2d0",
"keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量"
}
\ No newline at end of file
# 采用插入排序,按照字符顺序从小到大进行排序
【问题描述】
编写一个程序,从键盘接收一个字符串(长度不超过20),采用插入排序,按照字符顺序从小到大进行排序,最后输出排序后的字符串。
【输入形式】
输入一行字符串,长度不超过20。
【输出形式】
输出排序后的字符串。
【样例输入】
H2e3L*Lo,Wor#Ld.
【样例输出】
#*,.23HLLLWdeoor
## template
```cpp
#include <stdio.h>
#include <string.h>
int main()
{
char a[21];
scanf("%s",a);
int t,j=0,i=0;
int n = strlen(a);
for(j=1;j < n; j++){
for(i=0;i<j;i++) {
if (a[i] > a[j]) break;
}
int t=a[j];
int t1;
for(;i<=j;i++){
t1=a[i];
a[i]=t;
t=t1;
}
}
printf("%s",a);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4752d95a37c34f7dbdea1bda8279c2e5",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3c2a4c175f0247099e38df4250fe0483",
"keywords": "数学运算"
}
\ No newline at end of file
# 计算第n项的值
计算 s=(1+1)+(1+2)+(1+2+3)+````+(1+2+3+...+n) 第n项的值
## template
```cpp
#include <iostream>
using namespace std;
int main()
{
int n;
static int sum=1;
cout << "请输入N:" << endl;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
sum = sum + j;
}
}
cout << "结果为:" << sum;
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b16b92f28138483098175bd8f613ce8e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "665da4166519448eac5c20415f7f085a",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 数据合并
题目描述
将两个从小到大排列的一维数组 (维长分别为 m,n , 其中 m,n≤100) 仍按从小到大的排列顺序合并到一个新的一维数组中,输出新的数组.
输入描述
第 1行一个正整数 m , 表示第一个要合并的一维数组中的元素个数
第 2 行一个正整数 n , 表示第二个要合并的一维数组中的元素个数
第 3 行输入 m 个整数 (每个数用空格分开) , 表示第一个数组元素的值.
第 4 行输入 n 个整数 (每个数用空格分开) , 表示第二个数组元素的值.
输出描述
一行,表示合并后的数据,共 m +n 个数
样例输入
3
4
1 3 5
2 4 6 8
样例输出
1 2 3 4 5 6 8
要多组输入输出
## template
```cpp
#include <iostream>
using namespace std;
void merge(int * a1, int m, int * a2, int n)
{
int m1 = m - 1;
int n1 = n - 1;
for (int i = m + n - 1; i >= 0; i--)
{
if (m1 < 0) a1[i] = a2[n1--];
else if (n1 < 0) a1[i] = a1[m1--];
else if (a1[m1] < a2[n1]) a1[i] = a2[n1--];
else a1[i] = a1[m1--];
}
}
int main()
{
int m;
int n;
cin >> m;
cin >> n;
int a1[201];
int a2[101];
for (int i = 0; i < m; i++) cin >> a1[i];
for (int i = 0; i < n; i++) cin >> a2[i];
merge(a1, m, a2, n);
for (int i = 0; i < m + n; i++) cout << a1[i] << " ";
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-6a5398a4594f46c887e81037558fb371",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "5abe07db0c364778b4cfc2831a79a33b",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 最小公倍数
<p>从键盘输入两个正整数&#xff0c;求出它们的最小公倍数并输出所求结果。</p>
## template
```cpp
#include<stdio.h>
int main() {
    int m,n,temp,i;
    scanf("%d%d",&m,&n);
    if(m<n)
    {
        temp = m;
        m = n;
        n = temp;
    }
    for(i=m; i>0; i++)  
        if(i%m==0 && i%n==0)
        {
            printf("%d 和 %d 的最小公倍数是: %d\n", m, n, i);
            break;
        }
    return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-2a07209490ca4f5caecd6848360bab31",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d97abf9aa81047e394767a54e6b33c29",
"keywords": "算法高阶,数论算法,算法问题选编,RSA公钥加密系统"
}
\ No newline at end of file
# 编写一万年历系统(2021年)
<p>要求&#xff1a;模仿现实生活中的挂历。
当前页以系统当前日期的月份为准显示当前月的每一天(显示出日及对应的星期几)。
当系统日期变到下一月时,系统自动翻页到下一月。
 </p>
## template
```cpp
#include <stdio.h>
int year(int y)
{
if ((y%4==0) && (y%100!=0) || y%400==0)
return 366;
else
return 365;
}
int main()
{
int y;
int i,j,sum=0;
int begin,week;
int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
scanf("%d",&y);
for(i=1;i<y;i++)
sum+=year(i);
week=(sum+1)%7;
if(year(y)==366)
days[1]=29;
printf("\n%d年日历如下:\n\n",y);
for(i=0;i<12;i++)
{
printf(" %d月 \n",i+1);
printf(" 7 1 2 3 4 5 6\n");
printf("=====================\n");
begin=1;
for(j=0;j<week;j++)
printf(" ");
while(begin<=days[i])
{
printf("%3d",begin);
begin++;
week=(week+1)%7;
if(week%7==0)
printf("\n");
}
printf("\n\n");
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a323f28e4d5f439fb4caa921290996ef",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "139a13bdbcc94651ae75aaec25f1b88e",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 数组排序
定义一个包含5个整型元素(1, 5, 3, 92, 6)的数组,将数组元素按照由 小到大的顺序输出
## template
```cpp
#include <stdio.h>
#define N (int)5
int main()
{
int a[N] = {1,5,3,92,6};
int tmp;
for (int i = 0; i < N-1; i++)
{
for (int j = 0;j < N-1-i;j++)
{
if (a[j] > a[j+1])
{
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
}
}
for (int i = 0; i < N; i++)
{
printf("%d ",a[i]);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-c55e9f00626d484dbd4a8ee1481f06e5",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "5543e98792c54840a63492ce9d94766f",
"keywords": "算法高阶,矩阵运算,矩阵求逆,算法问题选编"
}
\ No newline at end of file
# 成绩问题
八个同学的语文数学成绩
每位同学的语文数学成绩比较,如果成绩都大于等于,则输出1;否则输出0.
最后形成一个八行八列的矩阵
## template
```cpp
#include <stdio.h>
int main()
{
int ch[8];
int ma[8];
for (int i = 0; i < 8; i++)
scanf("%d%d", &ch[i], &ma[i]);
for (int i = 0; i< 8; i++)
{
for (int j = 0; j < 8; j++)
if (ma[i] >= ma[j] && ch[i] >= ch[j])
printf("1 ");
else
printf("0 ");
printf("\n");
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-71481542bc1f41d782778a6d958e1806",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d0735910a0644b788594001562807ecd",
"keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术"
}
\ No newline at end of file
# 商家商品销售量统计
<p>现在有一个网站上半年的商品销售量,请你写一段代码帮助店主统计前半年的总销量和平均销量。
商品销售表
1月份 2月份 3月份 4月份 5月份 6月份 总销量 平均销量
64 53 77 59 61 42 0 0
(1)函数中应定义一个包含8个元素的一维数据,用来存放6个月的商品销量和统计后的总销量及平均销量;
(2)完成6个月销量的输入;
(3)计算半年的总销量及平均销量;
(4)按照程序运行效果图,输出商品销量表。
![图片说明](https://img-ask.csdn.net/upload/202005/16/1589596638_852927.jpg)</p>
## template
```cpp
#include<stdio.h>
int main()
{
int a[8],s=0;
printf("----------商家商品销售统计----------\n");
printf("\n");
printf("请输入商品6个月的销售量:");
for (int i = 0; i < 6; i++)
{
scanf("%d", &a[i]);
s += a[i];
}
printf("\n\t\t\t商品销量表\t\t\t\n");
printf("——————————————————————————————————————————————\n");
for (int i = 1; i <= 8; i++)
{
if (i <= 6)
printf(" %d月份 ", i);
else if (i == 7)
printf(" 总销售 ");
else
printf(" 平均销售 \n");
}
for (int i = 0; i < 8; i++)
{
if (i < 6)
printf(" %d |", a[i]);
else if (i == 6)
{
a[i] = s;
printf(" %d |", a[i]);
}
else
{
a[i] = s / 6;
printf(" %d |",a[i]);
}
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-7e4609d0b8b04353920cd3ae89b0fbe6",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3f7b074834bd4d0292a68756cd54e14b",
"keywords": "递归,数学运算"
}
\ No newline at end of file
# 求数列的第n项的值
已知数列:2,4,4,4,6,6,6,6,6,8,8,8,8,8,8,8,...求第n项的值
## template
```cpp
#include <iostream>
int main()
{
unsigned int N;
std::cout << "Please enter the value of N: ";
std::cin >> N;
if (N % 2 != 0)
{
std::cout << "Please enter an even number greater than zero!" << std::endl;
return -1;
}
int oddCount = 1;
int printCount = 0;
for (int i = 2; i <= N; i += 2)
{
for (int j = 0; j < oddCount; j++)
{
std::cout << i << " ";
printCount++;
if (printCount == N)
{
std::cout << "<---这个就是第N = " << N << "个数。" << std::endl;
return 0;
}
}
oddCount += 2;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a884036fe32548f4bba95b950da71ffb",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "df4ae221142740b48035c56c6c0a6646",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 计算函数的值
<p>编程输入实数x&#xff0c;计算下面函数的值&#xff0c;并输出y的值&#xff0c;并输出y的值&#xff1b;
x<sup>2</sup>         x&lt;1
3x-1      1≦x≦10
x/5        x&gt;10</p>
## template
```cpp
# include<stdio.h>
# include<stdlib.h>
int main(void)
{
float x,y;
printf("请输入x的值:\n");
scanf("%f",&x);
if(x<1)
{
y = x * x;
}
else if(x<=10)
{
y=3*x-1;
}
else
{
y= x / 5;
}
printf("y的值为:%f\n",y);
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-af64a6b7b1ff41edb539a85ee5cc6b83",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9ec6cd2edb454af5b555b50ac07d3077",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 统计某一单科成绩各分数段的分布人数
设某班有若干人,写一程序统计某一单科成绩各分数段的分布人数,每人的成绩随机输入,输入负数表示输入结束。要求按下面的格式输出统计结果(“**”表示实际分布人数)
0~39 **
40~49 **
50~59 **
……
90~100 **
## template
```cpp
#include <string>
#include <iostream>
using namespace std;
int main()
{
int result[12] = {0};
int gold;
while (cin>>gold) {
if (gold < 0) {
break;
}
int code = gold / 10;
if (code < 4) {
result[3] ++;
}
else if(code == 10) {
result[9] ++;
}
else {
result[code] ++;
}
}
string word[] = {"0~39",
"40~49",
"50~59",
"60~69",
"70~79",
"80~89",
"90~100"};
for (int i=0; i<7; i++) {
cout<<word[i]<<" "<<result[i+3]<<endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-f2381de2369d4c758ce2e8c8416ba5bb",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "b32f8aa2d40546458389237ecf23e5ef",
"keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 任意输入10数,存入数组,找出显示最大值,并且标记所在位置。
任意输入10数,存入数组,找出显示最大值,并且标记所在位置。
## template
```cpp
#include <stdio.h>
int main()
{
int a[10],i,max,maxindex;
for(i =0;i<10;i++)
scanf("%d",&a[i]);
max = a[0];
maxindex = 0;
for (i =1;i<10;i++)
{
if(a[i] > max)
{
max = a[i];
maxindex = i;
}
}
printf("最大值%d,索引:%d\n",max,maxindex);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-63617df530b3492fb51ffd35281fe398",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c3a291dbf54340bdb562c1ccd64afe4d",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 回文串
题目描述
回文串是从左到右或者从右到左读起来都一样的字符串,试编程判别一个字符串是否为回文串。
输入
输入一个字符串。串长度<255.
输出
判别输入的字符串是否为回文串,是回文串输出"Y",否则输出"N"。
样例输入
abcba
样例输出
Y
## template
```cpp
#include<iostream>
#include<string.h>
using namespace std;
int main(void)
{
char *p="abcba";
int n=strlen(p);
bool flag=1;
int i;
for(i=0;i<n/2;i++)
{
cout<<p[i]<<"\t"<<p[n-1-i]<<endl;
if(p[i]!=p[n-1-i])
{
flag=0;
cout<<"N"<<endl;break;
}
}
if(flag==1)
cout<<"Y"<<endl;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-0025b2f2ed7d4a1ab3345eb2e6860ea7",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "726563c7d75a4fc2b9bc75f147e0870c",
"keywords": "算法高阶,计算几何学,算法问题选编"
}
\ No newline at end of file
# 计算所有4位正整数中同时能被13和20整除的数的和
<p>计算所有4位正整数中同时能被13和20整除的数的和&#xff0c; 并同时做到如下显示:
①显示这些数:
②显示这些数的个数:
③显示这些数的和。</p>
## template
```cpp
#include "stdio.h"
int main()
{
int i = 1000;
int count = 0;
int sum = 0;
printf("所有4位正整数中同时能被13和20整除的数:\n");
for(i = 1000;i<10000;i++)
{
if(i % 13 == 0 && i % 20 == 0)
{
count++;
sum = sum + i;
printf("%d、",i);
}
}
printf("\n这些数一共有%d个\n",count);
printf("这些数的和是:%d\n",sum);
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-6bd048dcca094047afdca3604df6ac81",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "fb9b3c8ffc0c4246887769c963fa021e",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 输入某人的身高(厘米)和体重(公斤),按下式确定此人的体重是否标准、过胖或过瘦
<p>&#xff08;1&#xff09;标准体重&#61;&#xff08;身高-110&#xff09;公斤&#xff1b;
&#xff08;2&#xff09;超过标准体重5公斤为过胖&#xff1b;
&#xff08;3&#xff09;低于标准体重5公斤为过瘦。
例如&#xff1a;输入身高和体重分别为160&#xff0c;60&#xff0c;输出为过胖
输入身高和体重分别为160&#xff0c;50&#xff0c;输出为标准
输入身高和体重分别是160&#xff0c;40&#xff0c;输出为过瘦</p>
## template
```cpp
#include <stdio.h>
int main()
{
int h,w;
printf("请输入身高(厘米)和体重(公斤)");
scanf("%d %d",&h,&w);
int s = h - 110;
if( (w-s) > 5)
printf("过胖\n");
else if( s - w > 5)
printf("过瘦");
else
printf("标准\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-5d834145c66144fb88488488f2b26c76",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ea26060226394cf8be2482c2eb7f2e22",
"keywords": "回文,数学运算"
}
\ No newline at end of file
# 筛选10到1000的回文数
筛选出10到1000的回文数
## template
```cpp
#include <stdio.h>
int main()
{
int m,n,k;
for(m=1;m<=1000;m++)
{
k=m;
n=0;
while(k>0)
{
n=n*10+(k%10);
k=k/10;
}
if(m==n) printf("%d ", m);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-bc154609ec5d4feabc15d22fd34f3d84",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "e2ac2c36fe3b4993838520d66fffc6c5",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 统计各类字符个数
<pre><p>分别统计一个字符串中出现小写字母、大写字母、数字和空格的个数。
输入格式:
在一行中输入长度不超过40的字符串。
输出格式:
第一行中输出“小写字母&#61;x“ 第二行中输出“大写字母&#61;y“ 第三行中输出“数字&#61;z” 第四行中输出“空格&#61;m” 所有结果均原样输出&#xff0c;没有列宽控制。</p></pre>
<p>输入样例:</p>
<code>sd2h b57 sA</code>
<p>输出样例:</p>
<pre>
<code>小写字母&#61;5
大写字母&#61;1
数字&#61;3
空格&#61;2</code></pre>
## template
```cpp
#include<stdio.h>
int main()
{
int a=0,b=0,c=0,d=0,e=0;
char *p,str[80];
p=str;
gets(str);
while(*p)
if(*p>='A' && *p <='Z')
{a++;p++;}
else if(*p>='a' && *p <='z')
{b++;p++;}
else if(*p==' ')
{c++;p++;}
else if(*p>='0' && *p <='9')
{d++;p++;}
else
{e++;p++;}
printf("%d %d %d %d %d\n",a,b,c,d,e);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-2eb5f46d373e49f7817c5d8b2aa8254b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "42b783187e4d46468d090bc78fc827eb",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 请问如何实现这个代码的多组输入输出?
<p>给定 2 个正整数 a, b ,a 和 b 最多可能有 40 位,求出 a + b 的和。
输入描述
两个正整数 a, b,a 和 b 最多可能有 40 位。一行表示一个数。
输出描述
a + b 的和。</p><p>样例输入</p><pre><code class="language-" style="white-space: break-spaces;">111111111111111111111111111111111111111
222222222222222222222222222222222222222
</code></pre><p>样例输出</p><pre><code class="language-" style="white-space: break-spaces;">333333333333333333333333333333333333333
</code></pre>
## template
```cpp
#include <iostream>
#include <cstring>
using namespace std;
int main(){
while (1)
{
char s1[200],s2[200];
int a[200]={0},b[200]={0},l1,l2,c,k,i;
gets(s1);
l1=strlen(s1);
if (l1 == 0) break;
gets(s2);
l2=strlen(s2);
if(l1<l2) k=l2;
else k=l1;c=k;
for(i=0;i<l1;k--,i++)
a[k]=s1[l1-1-i]-'0';
for(k=c,i=0;i<l2;k--,i++)
b[k]=s2[l2-1-i]-'0';
for(i=c;i>=0;i--){
a[i]+=b[i];
if(a[i]>=10){
a[i]=10;
a[i-1]++;
}
}
if(a[0]!=0){
for(i=0;i<=c;i++)
cout<<a[i];
}else{
for(i=1;i<=c;i++)
cout<<a[i];
}
cout << endl;
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-05edbb7448fc4e2382440361b489b741",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3716e8b376e743f7b88f3cefbe33f59e",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 字符串排序
编写程序,输入若干个字符串。
要求:
(1)按字符串长度的大小升序输出各个字符串。
(2)按字符串中字符的ASCII码值大小升序输出各个字符串。
## template
```cpp
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool compare(string a,string b) {
if (a.length() != b.length()) {
return a.length() < b.length();
}
return a < b;
}
int main()
{
vector<string>list;
string inputString;
while (cin>>inputString) {
if (inputString == "0") {
break;
}
list.push_back(inputString);
}
sort(list.begin(),list.end(),compare);
for (int i=0; i<list.size(); i++) {
cout<<list[i]<<endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4702789f17414be98acf968f9796f0f5",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "e461ba15fbde4de2af31b9997670f397",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 冒泡法排序大小
4286
3185
2895
3550
2745
按从小到大排序
## template
```cpp
#include <stdio.h>
#define ARR_LEN 255
#define elemType int
void bubbleSort (elemType arr[], int len) {
elemType temp;
int i, j;
for (i=0; i<len-1; i++)
for (j=0; j<len-1-i; j++) {
if (arr[j] > arr[j+1]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
int main (void) {
elemType arr[ARR_LEN] = {4286,3185,2895,3550,2745};
int len = 5;
int i;
bubbleSort (arr, len);
for (i=0; i<len; i++)
printf ("%d\t", arr[i]);
putchar ('\n');
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-45eece006e934baab1f0ee2b5a54bb99",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ea7303fa0ac64727955304f3161f7b5c",
"keywords": "算法高阶,计算几何学,算法问题选编,确定任意一对线段是否相交"
}
\ No newline at end of file
# 用递归实现任意的正整数按反序输出
编写一个递归函数,将任意的正整数按反序输出。例如,输入"12345"输出"54321"
## template
```cpp
#include <iostream>
using namespace std;
void revert(int n)
{
if ( n>= 0 && n<= 9 )
{
cout<<n;
}
else
{
cout<<n % 10;
revert(n/10);
}
}
int main()
{
int n = 12345 ;
revert(n);
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-3f4bb4fd1b074661acb909e0877633eb",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2a7815ce93b942e5b79e561295f10440",
"keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量"
}
\ No newline at end of file
# 计算英文单词的能量值
<p>【问题描述】规定26个英文字符的能量值分别是1-26&#xff0c;键盘输入一个英文单词&#xff0c;输出它的能量值。字符不区分大小写。
【输入形式】在提示语后面输入一个单词
【输出形式】输出energy&#61;计算值
【样例输入1】Input a word:Integrity
【样例输出1】energy&#61;127
【样例输入2】Input a word:Upset
【样例输出2】energy&#61;81
【样例说明】下划线上是输入输出的数据&#xff0c;其余是程序的提示信息</p>
## template
```cpp
#include <stdio.h>
#include <cstring>
using namespace std;
#pragma warning(disable:4996)
int main()
{
int i;
int sum = 0;
char arrs[1000];
printf("Input a word:");
while (scanf("%s", &arrs) != EOF) {
sum = 0;
for (i = 0; i < strlen(arrs); i++) {
if (arrs[i] >= 'a') {
sum += arrs[i] - 'a' + 1;
}
else {
sum += arrs[i] - 'A' + 1;
}
}
printf("energy=%d\n", sum);
printf("Input a word:");
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-94936e5d40fc49f8b8ba0dd6c489dd47",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d7420933e1384b2086c75c7361f3f7bf",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 选择排序法
<p>使用选择排序法对10个整数进行由大到小排序。</p>
## template
```cpp
#include <stdio.h>
int main() {
int a[10];
int i,j,temp=0;
int k,x=0;
printf("输入10个数:\n");
for(i=0; i<10; i++)
scanf("%d",&a[i]);
for(i=0; i<9; i++) {
k = i;
for(j=i+1; j<10; j++)
if(a[j]<a[i])
k = j;
temp=a[i];
a[i]=a[k];
a[k]=temp;
}
printf("排序后:\n");
for(i=0; i<10; i++)
printf("%d ",a[i]);
getchar();
getchar();
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-fe9eff819a8b47c5a93796b9e248ec18",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "57c1f648d3e54869af5c8e09eb119efd",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 将其中每个单词的字母顺序翻转后打印输出到屏幕
<p>初始化一个字符数组为&#34;The best or nothing&#34;&#xff0c;并将其中每个单词的字母顺序翻转后打印输出到屏幕。要求&#xff1a;
1、字符数组的初始化在程序运行时由用户输入&#xff1b;
2、字符数组的翻转和结果输出功能通过函数实现&#xff1b;
3、字符数组不能定义成全局变量。</p>
## template
```cpp
#include <stdio.h>
#include <string>
void trans(char* p,int len)
{
char* s = new char[len];
memcpy(s,p,len);
for (int i = 0; i < len; i++)
{
p[i] = s[len-1-i];
}
delete[] s;
s = 0;
}
void transfun(char* p,int len)
{
int start = 0;
int i = 0;
int shift = 0;
while(i < len)
{
for (i = start; i < len;i++)
{
if(p[i] == ' ')
break;
}
trans(p+shift,i-start);
shift += i-start+1;
start = i+1;
i +=1;
}
}
void output(char* p)
{
printf("%s\n",p);
}
int main()
{
char buf[1000] = {0};
printf("请输入字符串:");
gets(buf);
transfun(buf,strlen(buf));
output(buf);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-3a790dc1352a41fa80785b3db03d3983",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c830e6fb1c0249baa955f67564dee393",
"keywords": "算法高阶,递归结构,高级数据结构,van Emde Boas树,原型van Emde Boas结构"
}
\ No newline at end of file
# 分支结构问题
<p>实现从键盘输入一个字符时&#xff0c;如果该字符为小写字母&#xff0c;则转换为大写字母输出&#xff1b;如果该字符为大写字母&#xff0c;则转换为小写字母输出&#xff1b;如果为其他字符&#xff0c;则原样输出。</p>
## template
```cpp
#include<stdio.h>
int main()
{
char x,y;
printf("请输入一个字符:");
scanf("%c",&x);
if(x>='A'&&x<='Z')
{
y=x+32;
printf("此字母是一个大写字母,转换后的小写字母是:%c",y);
}
else if(x>='a'&&x<='z')
{
y=x-32;
printf("此字母是一个小写字母,转换后的大写字母是%c",y);
}
else
{
printf("%c",x);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-1ccb6d649fde4ea9b5167b3c95ac20ac",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "bc0a339e536d4ebc9f7764d62bf6e7ae",
"keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术"
}
\ No newline at end of file
# 从键盘输入一组数据建立单链表,然后输出奇数位上的元素。
输入
第一行输入单链表长度n。
第二行输入字符串。
输出
第一行:输出各奇数位元素
样例输入
7
ABCDEFG
样例输出
ACEG
## template
```cpp
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
char x;
node * next;
} LList;
int main()
{
LList * header = NULL;
node * p;
int n;
scanf("%d", &n);
fflush(stdin);
for (int i = 0; i < n; i++)
{
if (!header)
{
header = (node *)malloc(sizeof(node));
p = header;
scanf("%c", &(header->x));
header->next = NULL;
}
else
{
p->next = (node *)malloc(sizeof(node));
p = p->next;
scanf("%c", &(p->x));
p->next = NULL;
}
}
p = header;
int i = 0;
while (p)
{
if (i++ % 2 == 0)
printf("%c", p->x);
p = p->next;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a620912b234a480dac7ffb01187f72ec",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "425ee9e06f9d442497d3c8b005c11f70",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 查找书籍
给定n本书的名称和定价,本题要求编写程序,查找并输出其中定价最高和最低的书的名称和定价。
输入格式:
输入第一行给出正整数n(<10),随后给出n本书的信息。每本书在一行中给出书名,即长度不超过30的字符串,随后一行中给出正实数价格。题目保证没有同样价格的书。
输出格式:
在一行中按照“价格, 书名”的格式先后输出价格最高和最低的书。价格保留2位小数。
输入样例:
3
Programming in C
21.5
Programming in VB
18.5
Programming in Delphi
25.0
输出样例:
25.00, Programming in Delphi
18.50, Programming in VB
## template
```cpp
#include<stdio.h>
struct book
{
float price;
char a[30];
};
int main()
{
int n;
scanf("%d",&n);
char a[30];
int i,k,maxi=0,mini=0;
book b[10];
for(i=0;i<n;i++)
{
fflush(stdin);
for(k=0;;k++)
{
b[i].a[k]=getchar();
if(b[i].a[k]=='\n')
{
b[i].a[k] = '\0';
break;
}
}
scanf("%f",&b[i].price);
}
for(i=1;i<n;i++)
{
if(b[i].price>b[maxi].price)
{
maxi=i;
}
if(b[i].price<b[mini].price)
{
mini=i;
}
}
printf("%.2f,%s\n",b[maxi].price,b[maxi].a);
printf("%.2f,%s",b[mini].price,b[mini].a);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-2830fd8ad9834b84a6fbded196a71233",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ecbceef80d8646a8b2d25262446b292f",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 计算阶乘的和
<p>计算1!-2!&#43;3!-4!&#43;5!-6!&#43;7!-8!&#43;9!-10!,并输出计算结果</p>
## template
```cpp
#include "stdio.h"
double fun(int n)
{
double sum=1.0;
int i;
for(i=1;i<=n;i++)
sum*=i;
return sum;
}
int main()
{
int i,mark=1;
double sum=0,item=0;
for(i=1;i<=10;i++)
{
item=mark*fun(i);
sum+=item;
mark=-mark;
}
printf("1!-2!+3!-4!+5!-6!+7!-8!+9!-10!=%.0lf\n",sum);
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-f5d98ab794124913a32e9c9d6c6b661e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d20cdebf0af94ddc84d23441f3a60084",
"keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法"
}
\ No newline at end of file
# 对数组中所有的数据按照输入先后顺序进行显示输出
<p>定义整数数组x&#xff0c;用键盘向数组输入10个数&#xff0c;输入之后&#xff0c;对数组中所有的数据按照输入先后顺序进行显示输出&#xff0c;最后设计一种算法&#xff0c;对数组中的数据进行升序排序&#xff0c;并输出排序后的数</p>
## template
```cpp
#include <stdio.h>
void Sortfun(double a[],int n)
{
int i,j;
double tmp;
for (i=0;i<n-1;i++)
{
for (j=0;j<n-1-i;j++)
{
if (a[j] > a[j+1])
{
tmp = a[j];
a[j] = a[j+1];
a[j+1]= tmp;
}
}
}
}
int main()
{
int i;
double a[10];
printf("请输入10个数:");
for(i =0;i<10;i++)
scanf("%lf",&a[i]);
printf("原顺序:\n");
for(i=0;i<10;i++)
printf("%g ",a[i]);
printf("\n");
Sortfun(a,10);
printf("排序后:\n");
for(i=0;i<10;i++)
printf("%g ",a[i]);
printf("\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-330873e9c5b04f739a87460a343a04f6",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "1c8b663380f4455fb806ecb69e8a3902",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 1,3,3,5,5,5,7,7,7,7,9,9,9,9,9,.....
<p><a href="http://114.67.86.56:5000/Problem_Show.asp?id&#61;1045">简单数列5</a><br />
<strong> </strong>已知一数列&#xff1a;1,3,3,5,5,5,7,7,7,7,9,9,9,9,9,11,11,11,11,11,11,11.....请根据规律求出第n项的值。例如&#xff1a;n&#61;4 项时&#xff0c;其值为5,n&#61;11时&#xff0c;其值为9.
<strong>输入格式 </strong>一个自然数n,(0&lt;n&lt;1000)<br />
<br />
<strong>输出格式</strong> 一个整数&#xff0c;即第n项的值。<br />
<strong>样例输入&#xff1a;4</strong><br />
<strong>样例输出 &#xff1a;5</strong></p>
## template
```cpp
#include <iostream>
using namespace std;
int main(){
int a,b;
cin>>a;
int n=1,count=1,num=1;
for(int i=0;i<a;i++)
{
if(count > n)
{
num+=2;
n++;
count=1;
i--;
}
else
{
cout << num << ",";
count++;
}
}
cout << endl;
cout << num;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-47ce0e1665cc43e792945a2c19873965",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "dc19c283474e42338ecb1bc684e63966",
"keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 找最大数和最小数
编写程序,设置正整数n的值,其中n取值为小于等于10的正整数,再继续输入n个整数数值,从n个整数中找出最大数和最小数,并将它们输出。
输入格式:
n的数值(取值为1-10整数)
n个具体整数值
输出格式:
最大值
最小值
输入样例1:
4
8 3 4 1
输出样例1:
8
1
输入样例2:
5
-1 6 3 2 0
输出样例2:
6
-1
## template
```cpp
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int ma, mi, a;
cin >> a;
mi = ma = a;
for (int i = 1; i < n; i++)
{
cin >> a;
if (ma < a) ma = a;
if (mi > a) mi = a;
}
cout << ma << endl << mi << endl;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-ebe18f7482904eff9930aa08489a0455",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4cf194b220ef438e9cde5a12353b3392",
"keywords": "数学,三角形"
}
\ No newline at end of file
# 判断是否能组成三角形
<p>根据输入的三角形的三边判断是否能组成三角形&#xff0c;若可以则输出它的周长和三角的类型</p>
## template
```cpp
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
int num1,num2,num3;
printf("请输入第一条边:");
scanf("%d",&num1);
printf("请输入第二条边:");
scanf("%d",&num2);
printf("请输入第三条边:");
scanf("%d",&num3);
if(num1+num2>num3&&num2+num3>num1&&num1+num3>num2)
{
if (num1*num1+num2*num2==num3*num3||num2*num2+num3*num3==num1*num1||num1*num1+num3*num3==num2*num2){
printf ( "%d、%d和%d可以组成直角三角形。\n " ,num1,num2,num3);
printf ("三角形周长:%d\n",num1+num2+num3);
}
else if (num1*num1+num2*num2<num3*num3||num2*num2+num3*num3<num1*num1||num1*num1+num3*num3<num2*num2)
{
printf ("%d、%d和%d可以组成锐角三角形。\n" ,num1,num2,num3);
printf ("三角形周长:%d\n",num1+num2+num3);
}
else{
printf ("%d、%d和%d可以组成钝角三角形\n" ,num1,num2,num3);
printf ("三角形周长:%d\n",num1+num2+num3);
}
}
else
printf("%d, %d和%d不能组成三角形。\n",num1,num2,num3);
system("PAUSE");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-5fad17086e2b4f8693887e5eeac0d5f0",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "83b4c5963f5a4aaf8f3d9db242f8fafb",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 设计一个“石头剪刀布”游戏程序。
<p>设计一个“石头剪刀布”游戏程序。用户和程序分别扮演猜拳双方&#xff0c;用户选择</p><p>石头、剪刀和布中的一项&#xff0c;程序随机选择另一项&#xff0c;与用户选择作比较&#xff0c;在界面中</p><p>显示最终的胜负判定。</p>
## template
```cpp
#include <stdlib.h>
#include <stdio.h>
int main()
{
int id;
int a[3]={1,2,3};
int au = 0;
while(1)
{
printf("1.剪刀,2.石头,3.布,0.退出\n");
scanf("%d",&id);
if(id == 0)
break;
au = a[rand()%3];
if (au == 1)
{
printf("机器:剪刀\t");
if(id == 1)
printf("玩家:剪刀\t平局\n");
else if(id == 2)
printf("玩家:石头\t玩家赢\n");
else
printf("玩家:布\t机器赢\n");
}
else if(au == 2)
{
printf("机器:石头\t");
if(id == 1)
printf("玩家:剪刀\t机器赢\n");
else if(id == 2)
printf("玩家:石头\t平局\n");
else
printf("玩家:布\t玩家赢\n");
}
else
{
printf("机器:布\t");
if(id == 1)
printf("玩家:剪刀\t玩家赢\n");
else if(id == 2)
printf("玩家:石头\t机器赢\n");
else
printf("玩家:布\t平局\n");
}
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-e32543ecfe3b41ae977d0f4f7326cafd",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f79aa282e9d94bdaa03348e902dd1a4c",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# n个素数的求和问题。
<p>给定n&#xff08;n≤100&#xff09;个正整数&#xff0c;所有正整数均≤1000000&#xff1b;求其中所有素数的和。
例如给定序列&#xff1a; 2 3 4 5 6&#xff0c;素数和为&#xff1a;10
给定序列&#xff1a; 3 4 5 6 7&#xff0c; 素数和为&#xff1a;15
给定序列&#xff1a; 12 19 23 35 68 71&#xff0c; 素数和为&#xff1a; 113
输入格式:
输入为两行。第一行是一个正整数n&#xff0c;表示有多少个数据。第二行是n个正整数组成的序列。
输出格式:
输出一个正整数&#xff0c;是上述序列中所有素数之和。</p>
## template
```cpp
#include <stdio.h>
int isprime( int n);
int main()
{
int i,n,m,s=0;
scanf("%d", &n);
for( i=0; i<n; i++ ) {
scanf("%d", &m);
if(isprime(m)){
s+=m;
}
}
printf("%d", s);
return 0;
}
int isprime(int n)
{
int i;
if(n<=1) return 0;
for(i=2;i*i<=n;i++)
if(n%i==0) return 0;
return 1;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-9345c837a02e4ad89496dbb2651bb04e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2b8e01617fb047b9bbfd3a0f5f680268",
"keywords": "算法高阶,计算几何学,算法问题选编,寻找最近点对"
}
\ No newline at end of file
# 总分数最大
<p>每位同学都有自己的一个幸运数&#xff0c;乐乐所在班级共有n位同学&#xff0c;因此有编号为1至n的n块标牌&#xff0c;标牌的编号与自己的幸运数相乘&#xff0c;就是这位同学的分数。你的工作就是帮乐乐寻找一种方案&#xff0c;使得班级总分数最大。
输入
第一行只有一个整数n
第二行共有n个不超过10000的正整数&#xff0c;中间有一个空格隔开。
输出
只有一行且只有一个整数&#xff0c;乐乐班级的总分数。</p>
## template
```cpp
#include<stdio.h>
int main()
{
int a[10005];
long long t=0;
int n,i,j,x;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(a[i]>a[j]){
x=a[i];
a[i]=a[j];
a[j]=x;
}
}
}
for(i=0;i<n;i++)
{
t+=a[i]*(i+1);
}
printf("%lld",t);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-c4855a030e9c46098e11829aad35cfaf",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "6744369a3e9e473a9121a29e1b8c67ca",
"keywords": "算法"
}
\ No newline at end of file
# 拆分数字
比如99 可以拆分为 9和9 9*9=81 81可以拆分为8和1 8*1=8 不能拆分了,得出结果为2
65可以拆分为6和5,6*5=30 30可以拆分为3和0,3*0=0 不能拆分了,得出结果也为2
实现这个功能 返回结果(结果为可拆分的次数)
## template
```java
public class HelloWorld {
public static int splitmul(int n) {
int r = 1;
while (n > 0) {
r *= (n % 10);
n /= 10;
}
return r;
}
public static void main(String[] args) {
int n = 99;
int x = n;
int t = 0;
while (x >= 10) {
x = splitmul(n);
System.out.println(x);
n = x;
t++;
}
System.out.println(t + "次");
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-617780d9404849e1b254f5a84afb1284",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "925c48eee7744e5ea30ca527bb70e93b",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# 打印1000以内的所有素数,并从键盘输入一个正整数,判断是否为素数。
<p>1、主类内至少两个方法&#xff0c;boolean prime(int p)方法和main()方法&#xff0c;prime方法判断参数p是否为素数。
2、1000以内的素数放入一个数组再打印。
3、单行风格,良好可读性,运行结果正确。</p>
## template
```java
import java.util.*;
public class Main {
public static void main(String[] args) {
List<Integer> numList = new ArrayList<>();
for(int i= 2;i<=1000;i++){
for(int j=2;j<=i;j++){
if(i%j==0&&j!=i){
break;
}else if(j==i){
numList.add(i);
}
}
}
System.out.println("1000以内的素数");
for(Integer integer : numList){
System.out.print(integer+" ");
}
System.out.println();
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
function function = new function();
System.out.println(function.prime(i));
}
}
class function{
public boolean prime(int p){
for(int i = 2;i<=(p/2);i++){
if(p%i==0&&p!=i){
return false;
}
}
return true;
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-b7d942b854f542759f13d5d986c3672c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "a13ce4d583b44d478ba4042a96b4d7d7",
"keywords": "数学,阶乘,算法"
}
\ No newline at end of file
# 求公式的值
求 1-1/2!-1/3! -... -1/10!
## template
```java
public class TEST {
public static double jiecheng(int n) {
double s = 1;
for (int i = 1; i <= n; i++)
s *= i;
return s;
}
public static double sum(int n) {
double sum = 0.0;
int s = 1;
for (int i = 1; i <= n; i++) {
sum += s / jiecheng(i);
s = -s;
}
return sum;
}
public static void main(String[] args) throws Exception {
int n = 10;
double ss = sum(n);
System.out.println(ss);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-63c2974977c340f99be3cb570db8a040",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "8f4e306342cc4ce784c7351c0796a3ad",
"keywords": "算法初阶,基础知识,算法基础,设计算法"
}
\ No newline at end of file
# 设计学生类Student和它的一个子类Undergraduate
<p>设计一个学生类Student和它的一个子类Undergraduate&#xff0c;要求如下&#xff1a;
(1)Student类有name和age属性&#xff0c;一个包含两个人参数的构造器&#xff0c;用于给两属性赋值&#xff0c;一个show()方法打印Student的属性信息。
(2)本科生类Undergraduate增加一个degree(学位)属性。有一个包含三参数的构造器&#xff0c;前两个参数用于给集成的属性赋值&#xff0c;第三个参数给degree专业见值&#xff0c;一个show()方法用于打印Undergraduate的属性信息。
(3)在测试类中分别打印Undergraduate和Student对象&#xff0c;调用它们的show()
 </p>
## template
```java
package T1;
public class Test {
public static void main(String[] args) {
Student stu = new Student("student", 100);
stu.show();
Undergraduate undergraduate = new Undergraduate("Undergraduate", 20, "本科");
undergraduate.show();
}
}
class Student {
private String name;
private int age;
public Student() {
super();
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void show() {
System.out.println("名字:" + this.name + "\t年龄:" + this.age);
}
}
class Undergraduate extends Student {
private String degree;
public Undergraduate(String name, int age, String degree) {
super(name, age);
this.degree = degree;
}
public void show() {
System.out.println("名字:" + super.getName() + "\t年龄:" + super.getAge() + "\t学位:" + this.degree);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-ebe62bf9f8b543f8950166e792801cce",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "318cf708eaa14db89f1a8feb60b757e6",
"keywords": "散列表,散列表,算法中阶,数据结构"
}
\ No newline at end of file
# 定义一个类Generator
<p>定义一个类 Generator&#xff08;生成器类&#xff09;&#xff0c;它可以在每次调用其 next()方法时&#xff0c;产生由你 最喜欢的电影&#xff08;如 Snow White 或 Star Wars&#xff09;的字符构成的名字&#xff08;作为 String 对象&#xff09;。在字 符列表中的电影名用完之后&#xff0c;循环到这个字符列表的开始处。使用这个生成器来填充数组、 ArrayList、LinkedList、HashSet&#xff0c;然后打印每一个容器。</p>
## template
```java
import java.util.*;
public class MovieGenerator {
private String[] movies = new String[] { "SS", "DD", "HH", "FF", "XX", "ZZ" };
private int i = 0;
public String next() {
return movies[i++ % movies.length];
}
public String[] getMovies() {
return movies;
}
public Collection<String> fill(Collection<String> collection) {
for (int i = 0; i < 8; i++) {
collection.add(next());
}
return collection;
}
public static void main(String[] args) {
MovieGenerator generator = new MovieGenerator();
System.out.println(Arrays.toString(generator.getMovies()));
System.out.println(generator.fill(new ArrayList<String>()));
System.out.println(generator.fill(new LinkedList<String>()));
System.out.println(generator.fill(new HashSet<String>()));
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-355b234cfee947a286f8c2ac76757717",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "32001819b93e48b49781d26600e0816b",
"keywords": "算法高阶,计算几何学,算法问题选编"
}
\ No newline at end of file
# 计算阶乘的和
编写程序计算1!+2!+3!+...+n!,并输出计算结果。(要求:n从键盘输入,0<=n<=50,如果输入的n值不在此范围,提示再次输入)
## template
```java
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone {
public static double p(int x) {
double r = 1.0;
for (int i = 2; i <= x; i++)
r *= i;
return r;
}
public static void main(String[] args) throws java.lang.Exception {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
if (n > 50 || n < 0) {
System.out.println("不在范围!");
} else {
double d = 0;
for (int i = 1; i <= n; i++)
d += p(i);
System.out.println("结果=" + d);
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-2ae799bf38f94a5abb4918c51365408b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "16faa740964a409498496ba5b6c9a812",
"keywords": "计算机"
}
\ No newline at end of file
# 获取硬盘信息
获取硬盘的分区信息,以及每个分区的磁盘空间及剩余空间
## template
```java
import java.io.File;
import java.text.DecimalFormat;
public class Ypxx {
public static void main(String[] args) {
File[] roots = File.listRoots();
for (File file : roots) {
System.out.println(file.getPath() + "信息如下:");
long free = file.getFreeSpace();
long total = file.getTotalSpace();
long use = total - free;
System.out.println("空闲未使用 = " + change(free) + "G");
System.out.println("已经使用 = " + change(use) + "G");
System.out.println("总容量 = " + change(total) + "G");
System.out.println("使用百分比 = " + bfb(use, total));
System.out.println();
}
}
public static long change(long num) {
return num / 1024 / 1024 / 1024;
}
public static String bfb(Object num1, Object num2) {
double val1 = Double.valueOf(num1.toString());
double val2 = Double.valueOf(num2.toString());
if (val2 == 0) {
return "0.0%";
} else {
DecimalFormat df = new DecimalFormat("#0.00");
return df.format(val1 / val2 * 100) + "%";
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-61fae25873944e15a4f49807b55df428",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "555fdeab64874a9eb3200a8864f60059",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 用0到9生成十位数的所有排列组合
用 0到9 生成 十位数的所有排列组合,数字0不能在第一个,这个生成的十位数,不能有重复的数字。
## template
```java
class java_234859 {
public static void main(String[] args) {
String str[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
permutation(str, 0, str.length);
}
static void swap(String[] str, int start, int end) {
String tmep = str[start];
str[start] = str[end];
str[end] = tmep;
}
static void permutation(String[] str, int start, int end) {
if (start == end - 1) {
for (int i = 0; i < end; i++) {
System.out.print(str[i]);
}
System.out.println();
} else {
for (int i = start; i < end; i++) {
if (i == 0 && str[0].equals("0"))
continue;
swap(str, start, i);
permutation(str, start + 1, end);
swap(str, start, i);
}
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-d530b1ea82ee486c9cced4ce5735514a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "1aa4ddebbd2a40408ba58e2da6922cf7",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 字符串统计
编写一个程序,对于输入的一段英语文本,可以统计:
1、该文本中有多少英语单词;
2、该文本中有多少不同的英语单词。
如,输入 I am a good student. I am in Zhengzhou.
则可以统计出有9个英语单词、7个不同的英语单词。
## template
```java
import java.util.HashMap;
import java.util.Map;
public class Tee {
public static String formatInput(String input) {
if (input == null) {
return null;
}
return input.replaceAll("[.|;|\\?]", " ");
}
public static Map<String, Integer> countWords(String input) {
Map<String, Integer> result = new HashMap<String, Integer>();
if (input == null || input.length() == 0) {
return result;
}
String[] split = input.split(" ");
if (split == null || split.length == 0) {
return result;
}
for (String value : split) {
if (result.containsKey(value)) {
result.put(value, result.get(value) + 1);
} else {
result.put(value, 1);
}
}
return result;
}
public static void main(String[] args) {
String value = "I am a good student.I am in Zhengzhou.Ha?";
String format = formatInput(value);
System.out.println(format);
Map<String, Integer> r = countWords(format);
System.out.println(r.toString());
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-5dc110c925a34f3eb0dce1d70824df90",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "fd98b6036cb145f783f87301e08148dc",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 找质数
找出大于200的最小的质数
## template
```java
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone {
public static void main(String[] args) throws java.lang.Exception {
int n = 201;
while (true) {
boolean b = true;
for (int i = 2; i < n / 2; i++) {
if (n % i == 0)
b = false;
}
if (b)
break;
n++;
}
System.out.println(n);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-533386f322a14d82b3a177257388740e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9857527a6db347778224967fcc9565a0",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 用数组写水仙花数
定义一个整型数组 a[7],在控制台输入任意的 7 个整数给数组赋值,输出数组中所 有的“水仙花数”。“水仙花数”是指一个三位数其各位数字的立方和等于该数本身。
## template
```java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int arr[] = new int[7];
System.out.println("请输入7个三位数:");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
System.out.println("数组中的水花仙数为:");
for (int i = 0; i < arr.length; i++) {
int x = arr[i] / 100;
int y = arr[i] / 10 % 10;
int z = arr[i] % 10;
if (arr[i] == x * x * x + y * y * y + z * z * z)
System.out.println(i);
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-a2c4b875a9d94ac7884cf17bf05ea936",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "87b8489903eb44c9a4256e4ccfc1e3a9",
"keywords": "数学"
}
\ No newline at end of file
# 输出每天是应该学习还是休息还是锻炼
<p>30天中&#xff0c;从第一天开始五天学习&#xff0c;一天休息、一天锻炼&#xff0c;输出每天是应该学习还是休息还是锻炼</p>
## template
```java
public class HelloWorld {
public static void main(String []args) {
int n1=0,n2=0,n3=0,i;
for(i=1;i<=30;i++){
if(n1<5){
System.out.println("学习");
n1++;
continue;
}
else{
System.out.println("休息");
System.out.println("锻炼");
n1=0;
i++;
}
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-fc71c8bf9ad34b9981d981739a3901dd",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2c42c52d1dcd4caeb5b603a6b00e63e1",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 按以下要求实现程序功能
<p>从键盘输入5个整型值
1&#xff09;按从大到小顺序排序方法&#xff1b;
2&#xff09;计算这些数的平均值的方法&#xff1b;
3&#xff09;在主方法中调用这些方法&#xff0c;并输出相应的值。</p>
## template
```java
import java.util.*;
class java_7445932 {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
for (int a = 1; a < 6; a++) {
System.out.print("请输入第 " + a + " 个值:");
list.add(scanner.nextInt());
}
System.out.println(descending(list));
System.out.println(getAvg(list));
}
public static List<Integer> descending(List<Integer> list) {
list.sort(Collections.reverseOrder());
return list;
}
public static Double getAvg(List<Integer> list) {
return list.stream().mapToInt(Integer::new).average().getAsDouble();
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-fae25413db4f43c7ae42fd6cda8ac0cc",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f60d640c19e2400bbd9315925042acb2",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 数组排序
<p>编写一个JavaApplication程序,将随机生成的无序数组使用冒泡排序,将这个混乱的数组变成一个从小到大排列的有序的数组并输出。</p>
## template
```java
class demo_sort {
public static void main(String[] args) {
int[] numbers = new int[] { 1, 5, 8, 2, 3, 9, 4 };
for (int i = 0; i < numbers.length - 1; i++) {
for (int j = 0; j < numbers.length - 1 - i; j++) {
if (numbers[j] > numbers[j + 1]) {
int temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
System.out.println("从小到大排序后的结果是:");
for (int i = 0; i < numbers.length; i++)
System.out.print(numbers[i] + " ");
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-e0913207bfe2490b863e4922c0a38bbe",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4a4e4dbc744b420395326ceacc36541a",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 用随机数相关知识解答随机分组问题
已知有16只男子足球队参加2008年奥运会。写一段程序将球队随机分成4组
## template
```java
import java.util.*;
class StringToDateDemo {
public static void main(String args[]) {
ArrayList<String> teams = new ArrayList<String>() {
{
add("a");
add("b");
add("c");
add("d");
add("e");
add("f");
add("g");
add("h");
add("i");
add("j");
add("k");
add("l");
add("m");
add("n");
add("o");
add("p");
}
};
Collections.shuffle(teams);
ArrayList<String> group1 = new ArrayList<String>();
ArrayList<String> group2 = new ArrayList<String>();
ArrayList<String> group3 = new ArrayList<String>();
ArrayList<String> group4 = new ArrayList<String>();
group1.addAll(teams.subList(0, teams.size() / 4 + teams.size() % 4));
group2.addAll(teams.subList(teams.size() / 4 + teams.size() % 4, 2 * teams.size() / 4 + teams.size() % 4));
group3.addAll(teams.subList(2*teams.size() / 4 + teams.size() % 4, 3 * teams.size() / 4 + teams.size() % 4));
group4.addAll(teams.subList(3*teams.size() / 4 + teams.size() % 4, teams.size()));
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-24d18232e86c4174be3d8ec4d800945a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f28969aa7f2247ddb2f1ca185b4d1e6d",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 数组元素统计
<p>定义一个长度为5的数组arr1&#xff0c;用于存放5个1~9的随机整数&#xff08;范围包含1和9&#xff09;&#xff0c;再定义一个长度为2的数组arr2&#xff0c;统计arr1中的元素对2求余等于0的个数,保存到arr2[0], 统计arr1中的元素对3求余等于0的个数,保存到arr2[1],在控制台打印输出arr2的所有元素</p>
## template
```java
package com.auskat.demo.cc;
import java.util.Random;
public class RandomTest {
public static void main(String[] args) {
int arr1[] = new int[5];
for (int i = 0; i < arr1.length; i++) {
arr1[i] = new Random().nextInt(9) + 1;
}
int i2 = 0;
int j3 = 0;
for (int i = 0; i < arr1.length; i++) {
if (arr1[i] % 2 == 0) {
i2++;
}
if (arr1[i] % 3 == 0) {
j3++;
}
}
int arr2[] = new int[2];
arr2[0] = i2;
arr2[1] = j3;
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-1b0a3ac8d3bb450a90dd2233c3967449",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f5f0049052e944f69c1dd272fe0894dc",
"keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 求输入数字的平均值、最大值
<p>输入若干个数&#xff0c;设输入的第一个数n为后面要输入的数的个数&#xff0c;求平均值及最大值&#xff0c;并在屏幕输出来</p>
## template
```java
import java.util.Scanner;
public class Test{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("输入n:");
int n=in.nextInt();
int temp,max=0,sum=0;
for(int i=0;i<n;i++){
temp=in.nextInt();
if (temp>max){
max=temp;
}
sum+=temp;
}
System.out.println("最大值为:"+max+",平均值为:"+sum*1.0/n);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-01bf0a868a4340fcbcc94f83cc60654b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "13f7e249328c407b8cde097d294a1101",
"keywords": "遍历"
}
\ No newline at end of file
# 对给定的两个日期之间的日期进行遍历
对给定的两个日期之间的日期进行遍历,比如startTime 是 2014-07-11;endTime 是 2014-08-11 如何把他们之间的日期获取并遍历出来。
## template
```java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class SplitTime {
private static List<Date> dateSplit(Date startDate, Date endDate) throws Exception {
if (!startDate.before(endDate))
throw new Exception("开始时间应该在结束时间之后");
Long spi = endDate.getTime() - startDate.getTime();
Long step = spi / (24 * 60 * 60 * 1000);
List<Date> dateList = new ArrayList<Date>();
dateList.add(endDate);
for (int i = 1; i <= step; i++) {
dateList.add(new Date(dateList.get(i - 1).getTime() - (24 * 60 * 60 * 1000)));
}
return dateList;
}
public static void main(String[] args) throws ParseException {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date start = sdf.parse("2015-4-20");
Date end = sdf.parse("2015-5-2");
List<Date> lists = dateSplit(start, end);
if (!lists.isEmpty()) {
for (Date date : lists) {
System.out.println(sdf.format(date));
}
}
} catch (Exception e) {
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-a9b7c9876f444128b028cf007af1bc34",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "6cf7562eaed24773b15849a107d866ed",
"keywords": "算法高阶,计算几何学,算法问题选编,确定任意一对线段是否相交"
}
\ No newline at end of file
# 找出出现次数最多的字符并计算次数
给定一个字符串“today is a special day”,长度任意,要求找出其出现次数最多的字符及计算次数。
## template
```java
import java.util.HashMap;
import java.util.Map;
class java_256052 {
public static void main(String[] args) {
String string = "Thinking in Java";
char[] ch = string.toCharArray();
Map<Character, Integer> result = new HashMap<Character, Integer>();
for (int i = 0; i < ch.length; i++) {
if (result.containsKey(ch[i])) {
int count = result.get(ch[i]) + 1;
result.put(ch[i], count);
} else {
result.put(ch[i], 1);
}
}
Character maxChar = null;
Integer maxCount = 0;
for (java.util.Map.Entry<Character, Integer> entry : result.entrySet()) {
if (entry.getValue() > maxCount) {
maxChar = entry.getKey();
maxCount = entry.getValue();
}
}
System.out.println("字符: " + maxChar + " 出现的字数最多,为 " + maxCount + " 次");
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-ab8c9f61d2b341668d2edc23ed0a5dd3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3fead7ec28fd4e08ab00069d593a8713",
"keywords": "算法初阶,快速排序,快速排序分析,排序和顺序统计量"
}
\ No newline at end of file
# 字符串排序
用main方法排序(按首字母或按字符串长度)
要求:
①输出原数组和排序后的数组
②若有“,”“.”不能进行排序,并将不符合排序要求的数组打印出来
③不能用API,可用选择、冒泡、快速
## template
```java
import java.util.Scanner;
class Untitled {
public static void main(String[] args) {
int num;
System.out.println("请输入数组元素长度:");
Scanner in = new Scanner(System.in);
num = in.nextInt();
System.out.println("请输入字符串:");
String str[] = new String[num];
for (int count = 0; count < num; count++) {
str[count] = in.next();
}
in.close();
System.out.println("before sorting:");
int c = 0;
for (int i = 0; i < num; i++) {
if (str[i].contains(",") || str[i].contains("."))
c++;
System.out.println(str[i]);
}
for (int i = 0; i < num - 1; i++) {
int min = i;
for (int j = i + 1; j < num; j++) {
if (str[min].contains(",") || str[min].contains("."))
min = j;
else if (str[j].compareTo(str[min]) < 0 && !str[j].contains(",") && !str[j].contains("."))
min = j;
}
if (min != i) {
String t = str[i];
str[i] = str[min];
str[min] = t;
}
}
System.out.println("after sorting:");
for (int i = 0; i < num - c; i++)
System.out.println(str[i]);
System.out.println("invalid items:");
for (int i = num - c; i < num; i++)
System.out.println(str[i]);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-784584d4042743b3bb7318e7a26e35c9",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "af0e6b33ab9b4ec190ccf64333a7313e",
"keywords": "算法"
}
\ No newline at end of file
# 买蛋
100元怎么买100个蛋,鸡蛋1毛一个,鸭蛋3元一个,鹅蛋6元一个
## template
```java
public class Egg {
public static void main(String[] args) {
int chicken = 0, duck = 0, goose = 0;
for (int i = 0; i < 100; i++) {
chicken = i;
for (int j = 0; j < 100; j++) {
duck = j;
goose = 100 - duck - chicken;
if (chicken + duck * 30 + goose * 60 == 1000 && chicken > 0 && duck > 0 && goose > 0) {
System.out.println("鸡:" + chicken + " 鸭:" + duck + " 鹅:" + goose);
}
}
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-4fac957b4a5b4a4bb422f94179a19397",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "0354ed691ce5411d81a24884a8494b7a",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 随机抽样
从数组a[]={1,2,3,4,5,6,7,8,9,10}中随机抽取5个数且不重复
## template
```java
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
class java_803899 {
public static void main(String[] args) {
int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Random r = new Random();
int count = 10;
while (count-- > 0) {
Set<Integer> result = new HashSet<Integer>(5);
while (result.size() < 5) {
int index = r.nextInt(10) % 10;
int currentData = a[index];
if (result.contains(currentData)) {
continue;
}
System.out.print("随机加入:" + currentData);
result.add(currentData);
}
System.out.println("第" + count + "次,last随机数:" + result);
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-8bb5829d421149898d51c15fc0931712",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "77a52d8fc8264e3aa07b40a6429c7d23",
"keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 按要求编写字符界面
编写一个字符界面的Java Application 程序,接受用户输入的10个整数,并输出这10个整数的最大值和最小值。
## template
```java
import java.util.Scanner;
public class MaxMin {
public static void main(String[] args) {
Arrays array = new Arrays();
array.setArr();
int max=array.getMax();
int min=array.getMin();
System.out.println("数组中最大值="+max);
System.out.println("数组中最小值="+min);
}
}
class Arrays {
private int[] arr;
public Arrays() {
arr = new int[10] ;
for(int i = 0; i<arr.length;i++) {
arr[i] =0;
}
}
public void setArr() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入数组元素的值:");
arr = new int[10] ;
for(int i = 0; i<arr.length;i++) {
arr[i] = sc.nextInt();
}
}
public int getMax() {
int max = arr[0];
for(int i : arr) {
if(max < i)
max = i;
}
return max;
}
public int getMin() {
int min= arr[0];
for(int i : arr) {
if(min > i)
min= i;
}
return min;
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-2f728b9b55b04f95b6a98da49a78858c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c176040947f346cd93bc21c102880af8",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 改写字符串
键盘录入一个字符串,将字符串中的大写改成小写,小写改成大写,数字改成*。例如heLLO123,输出后为HEllo***
## template
```java
import java.util.Scanner;
public class Transfer {
public static void main(String[] args) {
String str = "";
Scanner s = new Scanner(System.in);
System.out.println("请输入您想输入的字符串:");
str = s.next();
StringBuffer sb = new StringBuffer();
int i;
for (i = 0; i <= str.length() - 1; i++) {
char ch;
if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
ch = (char) (str.charAt(i) - 32);
} else if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
ch = (char) (str.charAt(i) + 32);
} else if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
ch = '*';
} else {
ch = str.charAt(i);
}
sb.append(ch);
}
String trStr = sb.toString();
System.out.println(sb.toString());
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-020381f9c5ed4d1cb82cc52d9be6cc82",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "59f634284442483f9508a7e5a429d533",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# 求素数
求1-100内的素数
## template
```java
public static void main(String[] args){
for(int i=0;i<100;i++) {
checkPrime(i);
}
}
private static void checkPrime(int x){
boolean isPrime = true;
if(x ==1 || x %2 ==0 && x !=2 )
{
isPrime = false;
}
else
{
for( int i =3; i< Math.sqrt(x); i+=2)
{
if( x % i == 0)
{
isPrime = false;
break;
}
}
}
if( isPrime)
{
System.out.println(x +"是素数");
}
else
{
System.out.println(x+ "不是素数");
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-aa64fac29ca84cefa805ada142a1e177",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "19c093ea3e24486e8c26d666a6738902",
"keywords": "排序"
}
\ No newline at end of file
# 逆序输出
如:abcd1234,逆序输出:4321dcba
## template
```java
import java.lang.*;
import java.io.*;
import java.util.*;
class ReverseString {
public static void main(String[] args) {
String input = "abcd1234";
char[] try1 = input.toCharArray();
for (int i = try1.length - 1; i >= 0; i--)
System.out.print(try1[i]);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-a5e75babe8bd4f1abc8508c7ac4b0822",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "06b91bca78894885b705e4342982b5c1",
"keywords": "算法初阶,基础知识,分治策略,用主方法求解递归式"
}
\ No newline at end of file
# 模拟计算器
模拟简单的计算器。
要求:
(1)定义名为Number的类,在其中定义两个私有的整型数据成员n1和n2;
(2)在Number类中编写构造方法,赋予n1和n2初始值;
(3)再为Number类定义加(addition)、减(subtration)、乘(multiplication)、除(division)四个公有成员方法,分别对两个成员变量执行加、减、乘、除的运算。注意:除法运算时要抛出除数为0的异常。
(4)在主方法中创建Number类的对象,调用上述各个方法,测试并输出计算结果,注意进行必要的异常捕获与处理。
## template
```java
public class Number {
private int n1;
private int n2;
public Number(int n1, int n2) {
this.n1 = n1;
this.n2 = n2;
}
public int addition() {
return n1 + n2;
}
public int subtration() {
return n1 - n2;
}
public int multiplication() {
return n1 * n2;
}
private int division() {
if (n2 == 0) {
throw new IllegalArgumentException("除数参数不合法");
}
return n1 / n2;
}
public static void main(String[] args) {
Number number = new Number(6, 0);
System.out.println(number.addition());
System.out.println(number.subtration());
System.out.println(number.multiplication());
try {
System.out.println(number.division());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-d6244fd716444192b25768d2c20c7ec8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "fb2fe931d6544b488fb9b2e75d24095a",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 生成随机字符串
生成一个由大写字母和数字组成的6位随机字符串,并且字符串不重复
## template
```java
class java_384519 {
public static char[] generate() {
char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
boolean[] flags = new boolean[letters.length];
char[] chs = new char[6];
for (int i = 0; i < chs.length; i++) {
int index;
do {
index = (int) (Math.random() * (letters.length));
} while (flags[index]);
chs[i] = letters[index];
flags[index] = true;
}
return chs;
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-42b9071735f94fd6a06af6be5535526f",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2d86a08f8cd04226a67a8be0f59fa0bc",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# 找出素数对
任意输入一个大于10的偶数编程找出所有和等于该偶数的素数对
## template
```python
h = 0
def a(h):
x = 0
for j in range(2, h):
if h % j == 0:
x = 1
break
if x == 0:
return 1
n = int(input("输入任意大于10的偶数:"))
for i in range(n,n+1):
h = 0
if i % 2 == 0:
for k in range(2, i):
if a(k) == 1 and a(i - k) == 1:
h = 1
if h == 0:
print("%d can't" % i)
break
else:
print("%d=%d+%d" % (i, k, i - k))
break
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-16830ba198e74b28884f2b840b1dd8dc",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "9721df86ceb94d2d970db129919a3f7b",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 要求编写函数fn(a,n) 求a+aa+aaa++⋯+aa⋯aa(n个a)之和,fn须返回的是数列和
<p>要求编写函数fn(a,n) 求a&#43;aa&#43;aaa&#43;&#43;&#43;aa⋯aa(n个a&#xff09;之和&#xff0c;fn须返回的是数列和。
从控制台输入正整数a和n的值&#xff08;两个值都不超过9&#xff09;&#xff0c;并输出fn(a,n)的结果值。</p>
## template
```python
def fun(a,n):
s = 1
sum = 1
for i in range(1,n):
s = 1 + s*10
sum+=s
y = a *sum
print(y)
def main():
while(1):
a = int(input('请输入a:'))
if a>9 or a<0:
print('a的值输入错误,请重新输入:')
else:
break
while(1):
n = int(input('请输入n:'))
if n>9 or n<0:
print('n的值输入错误,请重新输入:')
else:
break
fun(a,n)
if __name__ == '__main__':
main()
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-e71ae02a91a241958480070d13ce0cf8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "8c36458f4fe84d8ab901997bbe7ffb79",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 统计成绩分布
<p>随机产生10个[0&#xff0c;100]之间的整数&#xff0c;模拟5名学生的考试成绩。
要求:输出成绩&#xff0c;计算平均分&#xff0c;统计高于平均分的人数</p>
## template
```python
import random
a=[]
sum=0
cnt=0
for i in range(10):
x=random.randint(0,100)
sum+=x
print(x,end=" ")
a.append(x)
ave=sum/10
print()
print(ave)
for i in range(10):
if a[i]>ave:
cnt+=1
print(cnt)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-3172980559e74ba0bd8bf0c51fc3bd43",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "94ae135b4e7649779ffb44cb7b1e8022",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 输出整数的全排列
输入整数n(3<=n<=7),编写程序输出1,2,....,n整数的全排列,按字典序输出。
输入样例:
输入:3
输出:123 132 213 231 312 321
## template
```python
import random
n = int(input())
t = list()
t1 = set()
for i in range(1,n+1):
t.append(str(i))
while True:
sum = 1
for i in range(1, n + 1):
sum *= i
if len(t1) >= sum:
break
random.shuffle(t)
t1.add("".join(t))
s = sorted(t1)
for i in s:
print(i,end=" ")
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-9b12d14c8b3042e6b440425d1d4d98f9",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c060e90082694d4d94e9ea6bddebddd9",
"keywords": "数学,奇偶数"
}
\ No newline at end of file
# 输入起始和结束的正整数,求其两个正整数之间的偶数和。
<p>输入起始和结束的正整数&#xff0c;求其两个正整数之间的偶数和。</p>
## template
```python
x1 = input("请输入起始数:")
x2 = input("请输入结束数:")
a = int(x1)
b = int(x2)
sum1 = 0
for i in range(a, b+1):
if i % 2 == 0:
sum1 += i
i += 2
else:
i += 1
sum2 = 0
for i in range(a+1, b):
if i % 2 == 0:
sum2 += i
i += 2
else:
i += 1
print(str(a)+"到"+str(b)+"之间的偶数和(边界是偶数时算这两个边界)是:"+str(sum1))
print(str(a)+"到"+str(b)+"之间的偶数和(边界是偶数时不算两个边界)是:"+str(sum2))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-5197c9025b6a43799f9787b24e5f8254",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "db5ce3c1fe5e44028b44122ad42fcaf2",
"keywords": "图算法,算法高阶,图的表示,基本的图算法"
}
\ No newline at end of file
# 随机生成车牌号
<p>某市随机生成车辆号牌的规则是:号牌字头为"某A-","某B-"等(字母为除了C以外的A~H范围内的大写字母),字头后面由5位字符组成,第1位必须是数字;第2、3、4、5位可以是任意数字或不含字母"O"的大写英文字母。
程序功能为:调用自己设计的函数license_plate(),随机生成5个车辆号牌,等待输入一个心仪号码的序号选择号牌,并将其打印输出。
程序运行结果如下图所示:
![图片说明](https://img-ask.csdn.net/upload/201912/08/1575761967_651946.jpg)</p>
## template
```python
import random
def genrndchar(metachar):
return metachar[int(random.random() * len(metachar))]
def license_plate():
s = "某"
s = s + genrndchar(['A', 'B', 'C', 'D', 'E', 'H'])
s = s + '-'
s = s + genrndchar(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
for i in range(4):
s = s + genrndchar(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'])
return s
lst = []
for i in range(5):
plate = license_plate()
lst.append(plate)
print(str(i + 1) + ":" + plate)
x = int(input("请输入您心仪的号牌序号:")) - 1
print("您选中的号牌为:" + lst[x])
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-4188359eb0b14c92a03583f608f6ae2d",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "59b5475e8d294a01b10646731a5320b9",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 循环随机取数组直到得出指定数字?
举个例子:
随机数字范围:0~100
每组数字量:6(s1,s2,s3,s4,s5,s6)
第二轮开始随机数字范围:新s1和新s2取值为旧s1和s2之间,新s3和新s4取值为旧s3和s4之间,新s5和新s6取值为旧s5和s6之间。
跳出循环条件:任意数字=37
如因s1=s2!=37&&s3=s4!=37&&s5=s6!=37使数组进入无意义无限循环,则重新取0~100六个数字并开始如上述第二轮随机的随机取值。
## template
```python
import random
def random_test():
rst_list = [random.randint(0,100) for i in range(0, 6)]
print(rst_list)
while 1:
temp = []
for k,v in enumerate(rst_list):
if k%2==0:
temp.append(random.randint(min([rst_list[k],rst_list[k+1]]),max([rst_list[k],rst_list[k+1]])))
else:
temp.append(random.randint(min(rst_list[k-1], rst_list[k]),max(rst_list[k-1], rst_list[k])))
rst_list = temp
print(rst_list)
if 37 in rst_list:
print('rst_list:',rst_list)
return rst_list
else:
if rst_list[0]==rst_list[1] and rst_list[2]==rst_list[3] and rst_list[4]==rst_list[5]:
rst_list = [random.randint(0, 100) for i in range(0, 6)]
def main():
random_test()
if __name__ == '__main__':
main()
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-3c6e605603324dc5b91e1174ae595ae7",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "7bab6cd55b94429685debf5cf58f272d",
"keywords": "散列表,散列表,算法中阶,数据结构"
}
\ No newline at end of file
# 将一个列表中字典字段相同的元素合并并且值相加
如下两个列表,需要将oldList转化为newList,去掉相同字段的字典,并且去掉的参数里面的值要相加
oldList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1972},
{'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},
{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1450},
{'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},
{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1334}]
newList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 4756},
{'3-3': 406, '3-2': 0, '3-1': 0, '3-0': 0}]
## template
```python
import operator
oldList = [{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1972},
{'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},
{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1450},
{'3-3': 203, '3-2': 0, '3-1': 0, '3-0': 0},
{'0-0': 0, '0-1': 0, '0-2': 0, '0-3': 1334}]
newList = []
newList.append(oldList[0])
for t in range(1,len(oldList)):
for li in newList:
if operator.eq(li.keys(), oldList[t].keys()):
for key in li.keys():
li[key] += oldList[t][key]
break
elif operator.eq(li,newList[-1]):
newList.append(oldList[t])
break
print(newList)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-643e5cacb0564d7caad9f6342ea622f4",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "fcbac73829ed441e9a09c9113939e377",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# python 输出不重复的字符
<pre><p>输入一个字符串&#xff0c;把最左边的10个不重复的字符&#xff08;大小写算不同字符&#xff09;挑选出来。 如不重复的字符不到10个&#xff0c;则按实际数目输出。
输入格式:
输入一个字符串s。
输出格式:
输出一个字符串&#xff0c;包含字符串s最左边10个不重复的字符。不到10个按实际输出。</pre>
输入样例1:</p>
<code>Hello world, hello python</code>
<p>输出样例1:</p>
<pre>
<code>Helo wrd,h</code></pre>
<p>输入样例2:</p>
<pre>
<code>succeed</code></pre>
<p>输出样例2:</p>
<pre>
<code>suced</code></pre>
## template
```python
def unique(s):
set1 = set([])
out = ""
for i in range(len(s)):
c = s[i]
if c not in set1:
out = out + c
set1.add(c)
return out[0:10]
def main():
strin = "Hello world, hello python"
ret = unique(strin)
print(ret)
if __name__ == '__main__':
main()
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-cb343c4ab4a74e79b43d9971e4be38c2",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "dd93508e602f4ba487189a75f1a88295",
"keywords": "排序"
}
\ No newline at end of file
# 以特殊格式处理连续增加的数字
给出一串数字, 程序要把数字按照这样的格式输出,把连续增加的数字用 [x-y] 的形式表示,只显示这一组顺序数字的首位两个数字,不连续增加的数字单独列出。 例如:
输入:1, 2, 3, 4, 5, 8, 10, 11, 12, 13, 20, 21, 22;
输出:[1-5] [8] [10-13] [20-22]。
## template
```python
seq = list(map(int, input().split(',')))
tmp = [seq[0]]
all_list = []
for n in range(len(seq)):
if n == len(seq) - 1:
all_list.append(tmp)
break
if seq[n + 1] - seq[n] == 1:
tmp.append(seq[n + 1])
else:
all_list.append(tmp)
tmp = [seq[n + 1]]
for a in all_list:
if len(a) > 1:
print('[%s-%s]' % (a[0], a[-1]))
else:
print('[%s]' % a[0])
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-ade1ddc1d0ed47b597bf40fdf4afc2b1",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "0ca48be198f645a4b4dfcf927c191c63",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 冒泡排序
<p>用冒泡排序编写一个函数&#xff0c;允许接受多个数字的输入&#xff0c;不使用sort方法&#xff0c;给数字从小到大排序&#xff0c;最终输出从小到大的列表。</p>
## template
```python
#!/usr/bin/python3
def bubbleSort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
x=input("请输入数字,空格分隔:")
xlist=x.split(" ")
arr = [int(xlist[i]) for i in range(len(xlist))]
bubbleSort(arr)
print ("排序后的数组:")
for i in range(len(arr)):
print ("%d" %arr[i]),
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-a1f7e737a38644278f01470df3bcef0c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "046556412bf0440591213e99e6d2fc5e",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 计算出因子里面4和7的个数
<p>输入一个正数n&#xff0c;计算出因子里面分别有几个4和7&#xff0c;输出因子中4和7的个位数</p>
## template
```python
n = int(input("输入数字:"))
factor = [n]
num = 1
while num <= n/2+1:
if n % num == 0:
factor.append(num)
num = num + 1
print(factor)
m = [str(i) for i in factor]
count4 = 0
count7 = 0
for i in m:
if '4' in i:
count4 += 1
print('以4结尾的因子的个位数:', int(i)%10)
if '7' in i:
count7 += 1
print('以7结尾的因子的个位数:', int(i)%10)
print('因子里面分别有{0}个4和{1}个7'.format(count4,count7))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-af5bf32c62684037969e4c48658c5348",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "7e612dd7772a465099b20b31e8dcd4ce",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 字符串统计
<p>从键盘输入一个包含有英文字母、数字、空格和其它字符的字符串&#xff0c;并分别实现下面的功能&#xff1a;统计字符串中出现2次的英文字母&#xff08;区分大小写&#xff09;
统计字符串中出现n次的数字&#xff0c;n从键盘输入</p>
## template
```python
#第一题
s=input('input a string:\n')
dict1={}
for c in s:
if c.isalpha():
if c not in dict1.keys():
dict1[c] = 1
else:
dict1[c] += 1
for key in dict1.keys():
if dict1[key]==2:
print(key)
#第二题
s=input('input a string:\n')
n=int(input('input a n:\n'))
dict2={}
for c in s:
if c.isdigit():
if c not in dict2.keys():
dict2[c] = 1
else:
dict2[c] += 1
for key in dict2.keys():
if dict2[key]==n:
print(key)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-d520527fe78348048c1a484b072ebe74",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "7dfad301452a420cb7248656e7a8edce",
"keywords": "散列表,散列表,算法中阶,数据结构"
}
\ No newline at end of file
# 根据指定值从一个列表中查找所有匹配元素的位置,要求使用列表中的index方法进行查找。
<p><strong>题目内容&#xff1a;</strong>
编写程序实现以下功能&#xff1a;根据指定值从一个列表中查找所有匹配元素的位置&#xff0c;要求使用列表中的index方法进行查找。
 
<strong>输入格式:</strong>
先输入待查找元素的值。
再输入一个整数&#xff0c;表示列表中的元素个数。
最后依次输入列表中的元素。
 
<strong>输出格式&#xff1a;</strong>
输出一个列表&#xff0c;各元素值为匹配元素的位置。如果没有匹配元素&#xff0c;则输出一个空列表。
 
<strong>输入样例&#xff1a;</strong>
10
5
5
10
15
10
20
 
<strong>输出样例&#xff1a;</strong>
[1, 3]
 
<strong>输入样例&#xff1a;</strong>
30
5
5
10
15
10
20
 
<strong>输出样例&#xff1a;</strong>
[]</p>
## template
```python
check = input()
num = int(input())
list1 = []
for i in range(num):
x = input()
list1.append(x)
indices = []
start = 0
while 1:
try:
x = list1.index(check,start)
indices.append(x)
start = x+1
except:
break
print(indices)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-3dcdb18ef2b04145ac796966f6c7995c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c4cddca6661345f69da7dbb69f200ba8",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 生成100个2位随机正整数
<p>生成100个2位随机正整数&#xff0c;按每行十个输出&#xff0c;并求出个位数字分别为0,1,2,3,4,5,6,7,8,9的正整数的个数</p>
## template
```python
import random
def fun():
random_list = [random.randint(10, 99) for n in range(100)]
statistics = {n: 0 for n in range(10)}
for index, x in enumerate(random_list):
print(x, end=' ')
statistics[int(x % 10)] = statistics[int(x % 10)] + 1
if ((index + 1) % 10 == 0):
print()
print(statistics)
if __name__ == '__main__':
fun()
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-f3c11c2f317c47bca1104b4b85feef0b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "176794cad4f943c7a4d14c94992d08bf",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 任意多行字符串拆分数值求和
<pre><p>编写程序&#xff0c;统计每行字符串中若干整数的和。每行字符串中整数间的分隔符可能有逗号“,”、分号“ ;”和空格&#xff0c;有多少行就求多少行。
输入格式:
任意输入若干行由整数构成的字符串&#xff08;回车换行&#xff09;&#xff0c;整数间以逗号或空格或分号分隔。测试数确保至少有一行数据&#xff0c;字符串中的整数数据均合法有效。最后以一个回车结束输入。
输出格式:
对应输出原输入串&#xff08;一行中的字符序列&#xff09;&#xff0c;冒号后输出各个整数之和。
</pre><p>输入样例:</p></p>
<pre>
<code>1; 2 ,3
2 3; 4
10,20 30; 40
9</code></pre>
<p>输出样例:</p>
<pre>
<code>1; 2 ,3:6
2 3; 4:9
10,20 30; 40:100</code></pre>
## template
```python
stopword = ''
s = ''
print('请输入内容,输入空行回车结束输入:')
for line in iter(input, stopword):
s = s + line + "\n"
print(s)
l = s.splitlines()
for num in range(0, len(l)):
one = l[num].replace(',', ' ').replace(';', ' ').split()
onesum = 0
for i in range(0, len(one)):
onesum = onesum + int(one[i])
print(l[num] + ":" + str(onesum))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-756416220ab64f71a5835b9777756899",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "8854268b5aec411daa50dab57bb427a9",
"keywords": "猜大小"
}
\ No newline at end of file
# python 编程 猜数字
<p>游戏&#xff08;猜数字&#xff09;&#xff1a;随机生成一个数字&#xff08;取值范围&#xff3b;1&#xff0c;100&#xff3d;&#xff09;。让用户猜数字&#xff0c;并给出相应的提示&#xff1a;
如果用户输入比答案大&#xff0c;提示‘Too big&#xff0c; try again’&#xff1b;
反之&#xff0c;提示‘Too small, try again’&#xff1b;
如果猜中了&#xff0c;提示‘Congratulations!’。
最后&#xff0c;要给出反馈&#xff08;答案&#xff0c;猜的次数&#xff0c;猜的历史&#xff09;
 </p>
## template
```python
import random
v=random.randint(1,100)
count=0
his=[]
while 1:
vi=input("输入猜测值:")
count+=1
his.append(vi)
if int(vi)>v:
print("Too big,try again")
if int(vi)<v:
print("Too small,try again")
if int(vi)==v:
print('Congratulations!')
break
print("答案是:%d" % v)
print("猜测次数:%d" % count)
st=''
for i in his:
st+=i
st+=','
st=st[:-1]
print("猜测历史:%s" % st)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-d7c28e938ae14ccbaae1ca5b7dfcd01e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4f843138a8f7468dada93cbd95ab8d1f",
"keywords": "散列表,算法中阶,数据结构,散列函数"
}
\ No newline at end of file
# 编写Python程序实现素数处理的功能
<p style="margin-left:0cm; margin-right:0cm">编写Python程序实现素数处理的功能&#xff0c;要求如下&#xff1a;</p><p style="margin-left:0cm; margin-right:0cm">&#xff08;1&#xff09;从键盘输入一个整数X&#xff0c;编写一个函数Find&#xff08;x&#61;100&#xff09;&#xff0c;找出1—X之间的所有的素数&#xff08;即质数&#xff09;&#xff0c;并将这些素数按照升序存放在列表 prime_list []中。</p><p style="margin-left:0cm; margin-right:0cm">&#xff08;2&#xff09;在程序中编写一个函数delete_seven( prime_list)&#xff0c;将 prime_list []中个位含有7的素数删除&#xff1b;</p><p style="margin-left:0cm; margin-right:0cm"><strong>【程序要求&#xff1a;</strong></p><p style="margin-left:0cm; margin-right:0cm">&#xff08;1&#xff09;有引导用户键盘输入的提示信息&#xff0c;言语要恰当&#xff1b;</p><p style="margin-left:0cm; margin-right:0cm">&#xff08;2&#xff09;函数Find&#xff08;x&#61;100&#xff09;实现要正确&#xff0c;实现列表 prime_list []中查询到的素数的输出&#xff1b;</p><p style="margin-left:0cm; margin-right:0cm">&#xff08;3&#xff09;函数delete_seven( prime_list)实现正确&#xff0c;输出删除指定素数后的相关数据信息。</p>
## template
```python
def find(x=100):
pl = []
for m in range(2,x+1):
for k in pl:
if m % k == 0:
break
else:
pl.append(m)
return pl
def delete_seven(pl):
return [x for x in pl if x%10!=7]
x = int(input('输入一个整数:'))
prime_list = find(x)
print(prime_list)
print(delete_seven(prime_list))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-d285d1ea74954e309581b6e476b34d19",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "6562cc694a854024b5fe0ff3f5981415",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 新浪微博热门话题
<p>新浪微博可以在发言中嵌入“话题”&#xff0c;即将发言中的话题文字写在一对“#”之间&#xff0c;就可以生成话题链接&#xff0c;点击链接可以看到有多少人在跟自己讨论相同或者相似的话题。新浪微博还会随时更新热门话题列表&#xff0c;并将最热门的话题放在醒目的位置推荐大家关注。
 
本题目要求实现一个简化的热门话题推荐功能&#xff0c;从大量英文&#xff08;因为中文分词处理比较麻烦&#xff09;微博中解析出话题&#xff0c;找出被最多条微博提到的话题。
 
输入格式:
输入说明&#xff1a;输入首先给出一个正整数N&#xff08;≤10​5​​&#xff09;&#xff0c;随后N行&#xff0c;每行给出一条英文微博&#xff0c;其长度不超过140个字符。任何包含在一对最近的#中的内容均被认为是一个话题&#xff0c;输入保证#成对出现。
输出格式:
第一行输出被最多条微博提到的话题&#xff0c;第二行输出其被提到的微博条数。如果这样的话题不唯一&#xff0c;则输出按字母序最小的话题&#xff0c;并在第三行输出And k more ...&#xff0c;其中k是另外几条热门话题的条数。输入保证至少存在一条话题。
注意&#xff1a;两条话题被认为是相同的&#xff0c;如果在去掉所有非英文字母和数字的符号、并忽略大小写区别后&#xff0c;它们是相同的字符串&#xff1b;同时它们有完全相同的分词。输出时除首字母大写外&#xff0c;只保留小写英文字母和数字&#xff0c;并用一个空格分隔原文中的单词。
输入样例:
4
This is a #test of topic#.
Another #Test of topic.#
This is a #Hot# #Hot# topic
Another #hot!# #Hot# topic
输出样例:
Hot
2
And 1 more</p>
## template
```python
import re
a = int(input('输入微博数量(小于等于105的正整数):'))
b = []
c = []
while len(b)<a:
x = input('请输入微博内容,小于140字:')
if len(x)<140:
b.append(x)
else:
print('信息超出140字限制,请从新输入。')
c += re.findall('#[^#]+#',x)
d = [{'n':n,'c':len(c)-len(re.findall('#[^#]+#',re.sub(n,'',''.join(c.copy()))))} for n in set(c)]
e = sorted(d,key=lambda x:x['c'],reverse=True)
print(e[0]['n'].title())
print(e[0]['c'])
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-208c1edf3a3949d3b66d6faad5c76e6e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "108e622007174a6892619b47136060b3",
"keywords": "散列表,散列表,算法中阶,数据结构"
}
\ No newline at end of file
# Python编程 随机生成一个具有 20 个元素的元素值在 1-10 之间的列表
<p>随机生成一个具有 20 个元素的元素值在 1-10 之间的列表&#xff0c;输出连续最长数的个数。</p>
## template
```python
import random
a = [random.randint(1,10) for i in range(20)]
print(a)
l = rl = 1
n = rn = a[0]
for v in a[1:]:
if v==n:
l += 1
if l>rl:
rl = l
rn = v
else:
l = 1
n = v
print(f'连续最长的数是{rn},连续了{rl}次')
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-3ac147061a2244d19bd917bb3745e6af",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3b61f2fa4d7543ae8fd575ddbfa715de",
"keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术"
}
\ No newline at end of file
# 用Python来创造一个提示用户输入数字的乘法表?
<p>如果用户选择菜单选项1&#xff0c;提示用户输入1到10之间的整数&#xff0c;并打印一个乘法表&#xff0c;显示整数1与输入整数相乘的结果&#xff0c;如下面的示例所示。注意:不需要检查输入的数字是否在1到10之间。如果用户选择菜单选项2&#xff0c;退出程序。如果用户在菜单选择中输入了1或2以外的任何内容&#xff0c;输出信息“菜单选择错误&#xff0c;请重试并继续程序。”
结果应该如下&#xff1a;
1)创建乘法表
2)退出程序
请从以上菜单中选择一个选项:1
输入一个介于1到10之间的整数:3</p>
<p style="margin-left:0.5in; margin-right:0in">1  2  3 </p>
<p style="margin-left:0.5in; margin-right:0in">2  4  6 </p>
<p style="margin-left:0.5in; margin-right:0in">3  6  9 </p>
<p style="margin-left:0.5in; margin-right:0in"> 
1)创建乘法表
2)退出程序
请从以上菜单中选择一个选项:4
菜单选择错误&#xff0c;请重试
 
1)创建乘法表
2)退出程序
请从以上菜单中选择一个选项&#xff1a;2
谢谢你使用乘法表
 
 </p>
<p style="margin-left:0.5in; margin-right:0in"> </p>
## template
```python
while True:
print('1)创建乘法表')
print('2)退出程序')
n = input('请从以上菜单中选择一个选项:').strip()
if n=='1':
x = int(input('输入一个介于1到10之间的整数:'))
for i in range(1,x+1):
for j in range(1,x+1):
print("{:>4}".format(i*j),end="")
print()
elif n=='2':
print('谢谢你使用乘法表')
break
else:
print('菜单选择错误,请重试')
print('-----------------------------')
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-9eef6041a8104025ba01dae1553c662e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "89714e91b38049bebc0d21811744d00e",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# python 编写函数计算圆周率
<p>计算圆周率。存在圆心在直角坐标系原点且半径为 1 的圆及其外切正方形。为计算方便&#xff0c;仅考虑位于第一象限的四分之一正方形和四分之一圆。随机生成该四分之一正方形中一系列点&#xff0c;散布于四分之一圆内比例即为圆周率四分之一。散步点越多&#xff0c;结果越精确&#xff0c;耗时也越长。</p>
## template
```python
from random import random
from math import sqrt
N=eval(input("请输入次数:"))
K=0
for i in range(1,N+1):
x,y=random(),random()
dist =sqrt(x**2+y**2)
if dist<=1.0:
K=K+1
pi=4*(K/N)
print("圆周率值:{}".format(pi))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-2729238a246c41f9aca400eeeacb2ebb",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "10abb7399ddd40cdbe434a3ee1c96065",
"keywords": "散列表,散列表,算法中阶,数据结构"
}
\ No newline at end of file
# 列表奇偶拆分
<p>【问题描述】
输入一个列表&#xff0c;包含若干个整数&#xff08;允许为空&#xff09;&#xff0c;然后将其中的奇数和偶数单独放置在一个列表中&#xff0c;保持原有顺序
【输入形式】
【输出形式】
分两行输出&#xff0c;第一行输出偶数序列&#xff0c;第二行输出奇数序列
【样例输入1】
[48,82,47,54,55,57,27,73,86,14]
【样例输出1】
48, 82, 54, 86, 14
47, 55, 57, 27, 73
【样例输入2】
[10, 22, 40]
【样例输出2】
10, 22, 40
NONE
【样例说明】
如果奇偶拆分后&#xff0c;奇数列表&#xff0c;或者偶数列表为空&#xff0c;请直接输出NONE表示
 </p>
## template
```python
x = input()
x1 = x.strip('[]')
x2 = x1.split(",")
a = []
b = []
for i in x2:
if int(i) % 2 == 0:
a.append(i)
else:
b.append(i)
if a == []:
print("NONE")
else:
print(a)
if b == []:
print("NONE")
else:
print(b)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-8e0f43463d4f419ea58652f9c789e9a8",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "65e8ecd2065b4ee4827a8517319e873f",
"keywords": "算法初阶,基础知识,分治策略,最大子数组问题"
}
\ No newline at end of file
# 请问如何用python做两个数组逐位判断?
比如有以下数组:
a1: 1,0,0,1,0,0,0,1
a2: 0,0,0,0,1,1,1,1
a3: 0,1,0,1,0,1,0,0
a4: 1,0,1,1,1,1,0,0
a5: .......
抓取三个数组进行判断,
if ((a1第一位or a2第一位 or a3第一位=1 )and (a1第二位 or a2 第二位 or a3第二位=1)and....
直到判断完所有位数为止,所有位都有了1的话就输出当前这三个数组,已输出的数组不参与之后的判断。
## template
```python
# -*- coding: UTF-8 -*-
from itertools import combinations
a1=[ 1,0,0,1,0,0,0,1]
a2=[ 0,0,0,0,1,1,1,1]
a3=[ 0,1,0,1,0,1,0,0]
a4=[ 1,0,1,1,1,1,0,0]
a5=[ 1,1,1,1,1,1,1,0]
a6=[ 0,0,0,0,0,0,0,1]
a=[a1,a2,a3,a4,a5,a6]
al = list(combinations(a,3))
for i in al:
flag = True
for j in range(len(i[0])):
if (i[0][j] + i[1][j] + i[2][j] == 0):
flag = False
break
if flag:
print(i)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-d83b8a4176d64c129e3973a788923733",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c8f605e3f7254b9ea9559066514043f3",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 检查密码强度
<p>定义一个名为“isStrongPassword”的函数&#xff0c;该函数将字符串作为参数。功能然后将检查所提供的字符串是否满足以下条件&#xff0c;以检查是否为强
密码&#xff1a;
1.必须至少包含1个大写和小写字母的组合
2.必须至少包含3位数字
3.必须至少包含3个特殊字符&#xff08;包括空格&#xff09;
4.密码长度必须至少12个字符
该函数将返回一个布尔值&#xff0c;即如果满足所有条件则返回True或返回False
确保使用可能返回False值的每个可能的输入来测试函数也一样</p>
## template
```python
def isStrongPassword(pwd):
chars = list(pwd)
upper = [c for c in chars if 'A' <= c and c <= 'Z']
lower = [c for c in chars if 'a' <= c and c <= 'z']
digit = [c for c in chars if '0' <= c and c <= '9' ]
symbol = [c for c in chars if not ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z' or '0' <= c and c <= '9')]
strong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12
return strong
print(isStrongPassword("Str0n9P@$$w0rd"))
print(isStrongPassword("StrongPassword"))
print(isStrongPassword("Stron9P@$$0rd"))
print(isStrongPassword("Str0n9Pass0rd"))
print(isStrongPassword("str0n9p@$$0rd"))
print(isStrongPassword("Str0n9P@$$"))
print(isStrongPassword("12345678"))
print(isStrongPassword("~!@#$%^&*()_+"))
print(isStrongPassword("STRONGPASSWORD"))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-f32a0a63e34b4adb8c052728a097bd0f",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f7550974b1c54b2ba6d22d6ecaa97d27",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 编程通过键盘输入每一位运动员
<p>体操比赛成绩统计。多名运动员&#xff0c;多个评委打分&#xff0c;去掉一个最高分和去掉一个最低分&#xff0c;对其余分数求平均分作为一个运动员成绩。
编程通过键盘输入每位运动员编号和每个评委的成绩&#xff0c;求出运动员的最终成绩&#xff0c;并将运动员编号和最终成绩保存在一个字典中&#xff0c;形如{编号1:最终成绩1,学号2:最终成绩2.....&#xff0c;并将结果输出。</p>
## template
```python
t = int(input('请输入评委人数(不得少于3人):'))
s = int(input('请输入学生人数(不得少于1人):'))
stus = []
for i in range(s):
stu = {'score':[]}
stu.update({'sn':str(input('----\n请输入学生学号:'))})
for j in range(t):
stu['score'].append(input('请输入评委'+str(j+1)+'的评分:'))
stu['score'].sort()
stu.update({'min':stu['score'].pop(0)})
stu.update({'max':stu['score'].pop()})
stu.update({'avg':eval('+'.join(stu['score']))/len(stu['score'])})
stus.append(stu)
r = {n['sn']:n['avg'] for n in stus}
print(r)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-2fb024d58a9543e3944ef2df7680156b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "17bcbbd286c34a0f83c6edd18728337d",
"keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法"
}
\ No newline at end of file
# 求最大公约数和最小公倍数
<p>输入两个数x 和y&#xff0c;如果x 或y 小于等于0&#xff0c;提示请输入正整数&#xff0c;求这两个数的最大公约数和最小公倍数。
注意&#xff1a;可以采用欧几里得辗转相除算法来求最大公约数。最小公倍数的计算方法是两数的乘积除以两数最大公约数的结果。</p>
## template
```python
x = int(input("输入x:"))
y = int(input("输入y:"))
if x <= 0 or y <= 0:
print("请输入正整数")
if x < y:
x,y=y,x
v1 = x*y
v2 = x%y
while v2 != 0:
x=y
y = v2
v2 = x % y
v1 =v1/ y
print("最大公约数为:%d" % y)
print("最小公倍数为:%d" % v1)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-3ecfc8d4056446fc80f4660c9f783c20",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4d24654550a4451db8bff30d92a03e60",
"keywords": "散列表,算法中阶,数据结构,散列函数"
}
\ No newline at end of file
# 按要求实现程序功能
<p>&#xff08;1&#xff09;定义一个函数prime判断某个整数是否为素数&#xff1b;
&#xff08;2&#xff09;然后从键盘输入一行字符串&#xff0c;将其中的连续数字依次提取出来形成一个列表。例如&#xff0c;字符串“ab12cd34fg67”按要求提取后形成列表[12,34,67]&#xff1b;
&#xff08;3&#xff09;将列表中的所有非素数改为0&#xff08;要求用prime函数判断列表中的元素是否为素 数&#xff09;&#xff1b;
&#xff08;4&#xff09;输出原始字符串及修改前、修改后的列表。
提示&#xff1a;可以用s.isdigit()判断s是否为数字字符&#xff08;&#xff09;</p>
## template
```python
import math,re
def prime(num):
flag = False
if num > 1:
for i in range(2, math.floor(math.sqrt(num))):
if (num % i) == 0:
flag = True
break
if flag:
print(num, "不是素数")
else:
print(num, "是素数")
return flag
s = input("请输入字符串:")
sList = re.findall(r'(\d+)', s)
sNum = [int(x) for x in sList]
y = lambda x: 0 if prime(x) else x
sNew = [y(x) for x in sNum]
print(sNum)
print(sNew)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-cce2fe0fc7dc4983a33e0fbdbc220252",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ce1a6887e80947449a651d2d814e911e",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 移动字符串
给定一个字符串长度为 nn 的字符串 s1 (10<n<100) , 求出将字符串循环向左移动 k 位的字符串 s2 (1<k<n) , 例如:字符串 abcdefghijk , 循环向左移动 3 位就变成 defghijkabc
输入描述
输入仅两行,第一行为左移的位数 k , 第二行为字符串 s1 .
输出描述
输出仅一行,为将字符串 s1 左移 k 位得到的字符串 s2 .
样例输入
3
abcdefghijk
样例输出
defghijkabc
## template
```cpp
#include<iostream>
#include <string.h>
using namespace std;
void reverse(char *a,int start, int end)
{
int i ,j,temp;
for(i = start,j = end; i < j; i++,j--)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
void turnleft(char *a,int i,int n)
{
int left = i % n;
if(left == 0)
return ;
reverse(a,0,left-1);
reverse(a,left,n-1);
reverse(a,0,n-1);
return ;
}
int main()
{
char a[1024];
int i;
cin>>i;
cin>>a;
int n = strlen(a);
turnleft(a,i,n);
cout<<a<<endl;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b6011666ccf74dab86e27e7c98abeaa4",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "096ade2686cd427cad773afb42fa4d40",
"keywords": "算法初阶,基础知识,分治策略,证明主定理,对b的幂证明主定理"
}
\ No newline at end of file
# 完数
<pre>一个数如果恰好等于它的所有因子之和&#xff0c;这个数就称为“完数”。统计自然数 1 — 100 间完数的个数。</pre>
## template
```cpp
#include<stdio.h>
int perfect()
{
int i,x,sum,cnt=0;
for(i=1;i<=100;i++)
{
sum=0;
for(x=1;x<i;x++)
{
if(i%x==0)sum+=x;
}
if(i==sum)
{
cnt++;
printf("%d ",i);
}
}
return cnt;
}
int main()
{
printf("\ncount=%d\n",perfect());
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-0774741a0ab74418879c762b240e6cbd",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "102b29688e3b4777944f5df79c103019",
"keywords": "算法高阶,高级数据结构,不相交集合森林,用于不相交集合的数据结构"
}
\ No newline at end of file
# 好数对
已知一个集合A,对A中任意两个不同的元素求和,若求得的和仍在A内,则称其为好数对。例如,集合A={1 2 3 4},1+2=3,1+3=4,则1,2和1,3 是两个好数对。编写程序求给定集合中好数对的个数。
注:集合中最多有1000个元素,元素最大不超过10000
程序运行示例1:
4↙
1 2 3 4↙
2
程序运行示例2:
7↙
2456 3251 654 890 100 754 1234↙
1
其中,“↙”表示输入
## template
```cpp
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j,t;
scanf("%d",&n);
int* a = (int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int cout=0;
for( i=0;i<n;i++)
{
for( j=i+1;j<n;j++)
{
for(t = 0; t <n;t++)
if(a[i]+a[j]==a[t])
cout++;
}
}
printf("%d",cout);
free(a);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-07775d963c6347d6a2de39d53ee6e8a3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "6ff4d1c39dd84f60a0fd83ae52041ec6",
"keywords": "算法初阶,基础知识,随机算法,概率分析和随机算法"
}
\ No newline at end of file
# 难倒数万人的小学数学题
汉堡包在大街上大摇大摆的走着,看着手机上一道难倒数万人的小学数学题:
1 + 1 = 0
1 + 6 = 1
6 + 6 = 2
8 + 1 = 2
8 + 6 = 3
汉堡包看完之后发现上面这些加法的答案就是看1,6,8中圈圈的个数嘛!
突然之间,所有大厦上的LED屏幕上的广告全部变成数字1,6,8三个数字的随机闪现。
现给你一块n*m的LED屏幕,上面有且仅有一个数字(1,6,or 8),请你输出你看见的那个字母。
输入格式:
第一行输入两个整数n,m(2<= m, n <= 1000);
接下来n行,每行由m个数字0和1组成,其中1表示数字1,6,8的组成部分。
输出格式:
输出一个整数,代表图形表示的数字。
输入样例:
7 7
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 0 1 0 1 0 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
输出样例:
8
## template
```cpp
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
int main(){
int i,j,k=1;
int n,m;
int num[1010]={0};
int num_cmp=0;
int flag=1;
int led[1005][1005];
cin >> n >> m;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin >> led[i][j];
if(led[i][j]==1) num[k]++;
}
if(num[k]!=0)k++;
}
num_cmp=num[k-1];
for(i=k-1;i>0;i--){
if(num[i]<num_cmp) {
flag++;
num_cmp=num[i];
}
}
if(flag==1) cout <<"1"<<endl;
else if(flag==2) cout <<"8"<<endl;
else cout <<"6"<<endl;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a4a38346f8104f8693355716428b0945",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "7d6f241b860849c69f7bf557d0e87680",
"keywords": "约分,数学运算"
}
\ No newline at end of file
# 约分
编写程序,要求用户输入一个分数,然后将其约分为最简式。如:
输入一个分数:8/12
最简分式:2/3
## template
```cpp
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,x,y,c;
printf("输入一个分式:");
scanf("%d/%d",&a,&b);
if(a<b)
{
x=b;y=a;
}
else
{
x=a;y=b;
}
c=x%y;
while(c)
{
x=y;
y=c;
c=x%y;
}
if(b/y!=1)
printf("最简分式为:%d/%d",a/y,b/y);
else
printf("最简分式为:%d",a/y);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-bc60ad324b504a3a9e3b381a9b31debc",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "e8f39b5708714996a4cb24faba9df6e0",
"keywords": "算法,排序"
}
\ No newline at end of file
# 按字典顺序排列问题
输入若干英文单词,将每个单词的首字母转换成大写字母,其他字母为小写,并按字典顺序排列
## template
```cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void * a, const void * b)
{
return strcmp(*(char **)a, *(char **)b);
}
int main(int argc, char* argv[])
{
int n = 0;
int i;
printf("how many words?\n");
scanf("%d", &n);
char ** s = new char *[n];
for (i = 0; i < n; i++)
{
s[i] = new char[100];
scanf("%s", s[i]);
char * t = s[i];
while (*t != '\0')
{
if (t == s[i] && (*t >= 'a' && *t <= 'z')) *t = *t - 'a' + 'A';
if (t > s[i] && (*t >= 'A' && *t <= 'Z')) *t = *t - 'A' + 'a';
t++;
}
}
qsort(s, n, sizeof(char *), cmp);
for (i = 0; i < n; i++)
{
printf("%s\n", s[i]);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4beeb840810641d1af86e02854ab1ca3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "5d77aeeb61aa44b18a57ae9895d2feb3",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 国名排序
【字符数组】国名排序
Description:
小李在准备明天的广交会,明天有来自世界各国的客房跟他们谈生意,小李要尽快的整理出名单给经理,你能帮他把客户来自的国家按英文字典次序排好吗?
例如小李手上有来自加拿大,美国,中国的名单,排好的名单应是美国,加拿大,中国
Input
  第一行为一个n(n<=100)表示n个国家,第2行到第n+1行分别为n个国家的名字.
Output
  输出共计n行,为n个国家按字典顺序的排列,每行为一个国家
Sample Input:
3
China
Canada
America
Sample Output:
America
Canada
China
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
string a[1000];
int main()
{
int i,n;
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a[i];
}
for(i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(a[i]>a[j])
swap(a[i],a[j]);
}
}
for(int i=1;i<=n;i++)
cout<<a[i]<<endl;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-7610f054f0014548822e35c962241dd2",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "490fa532131f4fb18a915ea5820406a9",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 请问一共可以有多少种取木棍的方案
目前有一个长度为 n 的木棍,当做直角三角形的斜边。A,B,C要从许多整数长度的木棍中选出三根,分别长为 a, b, c。 现在,蒜头君和花椰妹的木棍组成一条直角边长度为 a + b,白菜君组成另外一条直角边 c,并且要求 a + b ≤ c。请问一共可以有多少种取木棍的方案。 提示:a = 3, b = 4 与 a = 4, b = 3 算作同一种方案。
## template
```cpp
#include <stdio.h>
int main()
{
int n;
int cnt = 0;
scanf("%d", &n);
for (int a = 1; a < n; a++)
for (int b = a; b < n - a; b++)
for (int c = 1; c < n; c++)
{
if ((a+b)*(a+b)+c*c==n*n)
{
printf("a=%d b=%d c=%d\n", a, b, c);
cnt++;
}
}
printf("一共有%d种方案", cnt);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-512a8f7a750c4a3bbe0b041461e1daae",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2dfca825483b4b27ba6efa2c18ea4b79",
"keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术"
}
\ No newline at end of file
# 报数游戏
<p><strong>题目描述</strong><br />报数游戏
首先&#xff0c;会给他们一人一个编号&#xff0c;并且每个人的编号都不相同。接下来的每一回合&#xff0c;会给一个数&#xff0c;编号超过它的最小编号的人要报出自己的编号。如果没有人的编号比给出的数要大&#xff0c;那么编号最大的人要报出自己的编号。每个人可以重复报号。
会按照一个列表顺次报出每个回合的数&#xff0c;朋友们想知道每回合报出的编号应该是多少。
<strong>输入</strong><br />输入数据共 3 行。
第一行有两个整数 n,m(1≤n≤100,000,1≤m≤100,000)&#xff0c;分别表示参与游戏的朋友的个数&#xff0c;和游戏的回合数。
第二行 n个整数 ai(1≤ai≤100,000,000)&#xff0c;表示朋友们每个人的编号。对于 0≤i&lt;j&lt;n&#xff0c;都有 ai&lt;aj&#xff0c;即他们的编号递增排列。
第三行 m 个整数 qi(1≤qi≤100,000,000)&#xff0c;表示每回合给的数字。
<strong>输出</strong><br />
输出共一行 m 个整数&#xff0c;表示每回合报出的编号&#xff0c;每两个整数之间一个空格&#xff0c;最后一个数后面没有空格。</p>
## template
```cpp
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int ai[100010], qi[100010];
int main()
{
int a, q;
while (cin >> a >> q)
{
for (int i = 0; i < a; i++)cin >> ai[i];
for (int i = 0; i < q; i++)cin >> qi[i];
for (int i = 0; i < q; i++) {
int left = 0, right = a - 1, mid;
while (left < right) {
mid = (left + right) >> 1;
if (ai[mid] <= qi[i])left = mid + 1;
else right = mid;
}
if (left - 1 < 0 || ai[left] < qi[i])left++;
i ? cout << " " << ai[left - 1] : cout << ai[left - 1];
}
cout << endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-fea6172102854a7d800ac1ee95fbd71c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "006e34ebcc264c63b8ad32e6b9413e83",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 不喜欢带钱的小C
题目描述:
小C不喜欢带钱,有一次竟被他碰上了一家不能使用移动支付(也不能找钱)的神秘商店。请问小C至少准备多少张RMB才能恰好支付n元。RMB的面额有100元,50元,20元,10元,5元,1元。
输入格式:
输入一个整数n
输出格式:
最少带几张。
样例输入1:
50
样例输出1:
1
约定:
1<=n<=100
## template
```cpp
#include <iostream>
using namespace std;
int solve(int tar, int * meta, int metan, int * seed = NULL, int seedn = 0)
{
if (tar == 0)
{
return seedn;
}
int min = -1;
int m;
int * seed1 = new int[seedn + 1];
if (seed)
memcpy(seed1, seed, sizeof(int) * seedn);
for (int i = 0; i < metan; i++)
{
if (meta[i] <= tar)
{
seed1[seedn] = meta[i];
m = solve(tar - meta[i], meta, metan, seed1, seedn + 1);
if (m != -1 && (min == -1 || min > m))
min = m;
break;
}
}
delete[] seed1;
return min;
}
int main()
{
int arr[] = { 100, 50, 20, 10, 5, 1 };
int n = 6;
int total;
cin >> total;
int result = solve(total, arr, n);
cout << result << endl;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-3e8ceb9f33ef479e856cb39951547d60",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "dc405e737aad44dc8ac5297afcb21e5c",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 字符图形输出
编程实现把输入任意整数n后,可打印出n行三角字符阵列图形。例如,输入整数5时,程序运行结果如下:
ENTER A NUMBER:5<回车>
A C F J O
B E I N
D H M
G L
K
## template
```cpp
#include <iostream>
using namespace std;
char a[100][100];
int main()
{
char c = 'A';
int n = 5;
for (int i = 0; i < n; i++)
{
for (int j = i; j >= 0; j--)
{
a[j][i - j] = c++;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - i; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-f89e828b62fe4a2f9e574e3ea30f9423",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "5d3839f1e71a4f88b1386d7724d05734",
"keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量"
}
\ No newline at end of file
# 数字归类
题目描述
一个数里面若含有数字1,则归类到1字类,含有数字2,则归类到2字类,所以一个数可能同时归类到不同的数字类。对于0、1、2、3、4、5、6、7、8、9这十个数字类,因研究需要,急于想知道某一堆数中,究竟归类到这些数字类的个数。
样例输入
123 456 175 2 61 9998 12 5053 382
样例输出
0: 1
1: 4
2: 4
3: 3
4: 1
5: 3
6: 2
7: 1
8: 2
9: 1
提示
注意:输出结果中冒号后面有空格
## template
```cpp
#include <stdio.h>
#include <string.h>
int result[10];
int main(void) {
memset(result, 0, sizeof(int) * 10);
int n;
int arr[10];
while (scanf("%d", &n) != EOF)
{
memset(arr, 0, sizeof(int) * 10);
if (n == 0) arr[0] = 1;
while (n > 0)
{
arr[n % 10] = 1;
n = n / 10;
}
for (int i = 0; i < 10; i++)
result[i] += arr[i];
}
for (int i = 0; i < 10; i++)
printf("%d: %d\n", i, result[i]);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4ccda2f0fcdb423a9b81405f96c28bdb",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "16516c31ba1049fb88f4e16d03d5c767",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 输出最长的递增数字字符串
<p>如何在一亿位整数组成的字符串中找到最长的递增数字字符串&#xff1f;</p>
## template
```cpp
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100000
int main()
{
char buf[MAX_SIZE] = {0};
int i = 0,len = 0,index = 0;
char maxbuf[12] = {0};
char maxbuf2[12] = {0};
int maxlen = 0;
gets(buf);
len = strlen(buf);
maxbuf2[0] = buf[0];
i = 1;
index = 1;
while(i < len)
{
if (buf[i] > buf[i-1])
{
maxbuf2[index] = buf[i];
index++;
}else
{
if (index > maxlen)
{
maxlen = index;
strcpy(maxbuf,maxbuf2);
maxbuf[index] = '\0';
maxbuf2[0] = buf[i];
index = 1;
}else
{
maxbuf2[0] = buf[i];
index = 1;
}
}
i++;
}
if (index > maxlen)
{
maxlen = index;
strcpy(maxbuf,maxbuf2);
maxbuf[index] = '\0';
}
printf("最大串长度:%d,字符串:%s\n",maxlen,maxbuf);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-fc5f981ecc0d4560bcd8de07ea1a21ce",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "1f485aabb88d4a5a81f0ddbe64d6aee1",
"keywords": "算法高阶,数论算法,元素的幂,算法问题选编"
}
\ No newline at end of file
# 目标值与数组所有元素去比对,找出最接近的元素,输出下标
举例如下:一个数组{915,941,960,976,992,1015,1034,1050,1073,1089,1115,1131,1150,1166,1182,1208,1227};目标值假设是1000,最接近元素为992,下标为4
## template
```cpp
#include <stdio.h>
int main()
{
int min = (1 << 31) - 1;
int idx = 0;
int arr[] = {915,941,960,976,992,1015,1034,1050,1073,1089,1115,1131,1150,1166,1182,1208,1227};
int n = 1000;
for (int i = 0; i < sizeof(arr) / sizeof(int); i++)
{
int diff = arr[i] - n;
if (diff < 0) diff = -diff;
if (diff < min)
{
min = diff;
idx = i;
}
}
printf("最接近的是%d 下标是%d", arr[idx], idx);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-913b1228d460449a84fc7c065de6dcc5",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "29d63b6df9784a0c90a46f36da67969f",
"keywords": "数学运算,图形输出"
}
\ No newline at end of file
# 输入一个正整数n(代表图形的行数),输出如样例形式的图形
输入:5
输出:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
## template
```cpp
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N - i; j++) printf(" ");
for (int j = 0; j < i; j++) printf("%c", (char)(j + 'A'));
for (int j = i; j >= 0; j--) printf("%c", (char)(j + 'A'));
printf("\n");
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a4dd4e1f5d08486991fa8e585f7cf593",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f2fbe20a4aba45a6be1d3b4f940a91e0",
"keywords": "算法高阶,数论算法,元素的幂,算法问题选编"
}
\ No newline at end of file
# 逆序存放数组中的数据,并输出指定元素
<pre><p>将给定的n个整数存入数组中&#xff0c;将数组中的这n个数逆序存放&#xff0c;再按要求输出指定的数组元素。
输入格式:
在第一行中给出一个正整数n&#xff08;1≤n≤10&#xff09;。第二行输入n个整数&#xff0c;用空格分开。第三行输入一个非负整数m&#xff08;m&lt;n&#xff09;
输出格式:
在一行中输出逆序存放后下标为m的数组元素。行末无空格。</pre>
输入样例:</p>
<pre>
<code>6
10 8 1 2 3 4
2</code></pre>
<p>输出样例:</p>
<pre>
<code>2</code></pre>
## template
```cpp
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m;
scanf("%d",&n);
if(n<1||n>10){
printf("1≤n≤10");
return 0;
}
int *a = (int*)malloc(sizeof(int)*n);
for(int i=n-1; i>=0; i-- ){
scanf("%d",&a[i]);
}
scanf("%d",&m);
if(m<0||m>=n){
printf("0≤m<n");
return 0;
}
printf("%d",a[m]);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-b4be2745af794dfc99330d13c942d443",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "bd646e2783ee458daec2e92c9d168967",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 移动数组中的字符
在数组中有n个字符,使前面各字符顺序向后移动m个位置,并使最后m个字符变成最前面的 m 个字符
## template
```cpp
#include <iostream>
using namespace std;
void funShift(int m,char *p,int n)
{
char c;
for (int j = 0; j < m;j++)
{
c = p[n-1];
for (int i = n-1; i > 0; i--)
{
p[i] = p[i-1];
}
p[0] = c;
}
}
int main()
{
int i,m,n;
cin >> m >> n;
char *p =new char[n+1];
p[n] = 0;
for(i = 0; i < n; ++i)
cin >> p[i];
funShift(m,p,n);
for(i = 0; i < n; ++i)
cout << p[i] << ' ';
cout << endl;
delete [] p;
getchar();
getchar();
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-d507bc1336234a4683dda08bccbac0ee",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "eb40a4f171bb4728acb3aef4f202ac25",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# 求前n个素数之和
题目描述
求前n个素数的和。
例如,前5个素数是2、3、5、7、11,它们的和是28。
输入
一个整数n,1<=n<=1000。
输出
前n个素数的和
样例输入
5
样例输出
28
提示
第1000个素数是7919。
## template
```cpp
#include <iostream>
using namespace std;
int main()
{
int n,i,j,sum,a;
cin>>n;
a = 0;
i = 2;
sum=0;
while(a<n){
for(j=2;j<=i;j++)
if(i%j == 0)
break;
if(j == i)
{
sum += i;
++a;
}
++i;
}
cout<<sum;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-e94da2e4d5264fe987a42c5c15c75113",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3fd95e3f9d8e4fecb5c48c87633516ce",
"keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数"
}
\ No newline at end of file
# 将一个字符串中第一个连续数字转换成整数
<p>请编写一个fun函数&#xff0c;实现如下功能&#xff1a;将一个字符串中第一个连续数字转换成整数&#xff0c;作为函数值返回&#xff0c;否则返回0&#xff08;程序的输入输出要有提示&#xff09;
比如&#xff1a;字符串中的内容为:&#34;abc123 def45gh&#34;&#xff0c;则函数的返回值为123。</p>
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
int fun(string str);
int main(void) {
string str = "abc123 def45gh";
cout << fun(str);
return 0;
}
int fun(string str) {
int index = -1;
int score = 0;
for (int i = 0; i < str.length(); i++) {
if ((str[i] >= 48 && str[i] <= 57) && (i + 1 < str.length()) && (str[i + 1] >= 48 && str[i + 1] <= 57)) {
index = i;
break;
}
}
if (index == -1) {
return score;
}
score = str[index] - '0';
for (int i = index + 1; i < str.length(); i++) {
if (str[i] >= 48 && str[i] <= 57) {
score *= 10;
score += str[i] - '0';
} else {
break;
}
}
return score;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-1c8e47bdacc74e7ca9ef4e73895b1929",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ed7b212163054519ab77895c91084826",
"keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量"
}
\ No newline at end of file
# 计算sin(x)
描述
计算sin(x)=x-x^3/3!+x^5/5!-X^7/7!+......,直到最后一项的绝对值小于10-7时停止计算。其中-2Π<=x<=2Π,^表示次方,如x^3表示x的3次方。
输入
一个实数x,-2Π<=x<=2Π
输出
sin(x)的值
输入样例 1
3.142
输出样例 1
-0.000407347
## template
```cpp
#include<stdio.h>
#include<math.h>
double sin(double);
double nResult(double,double);
int main()
{
double x=0;
scanf("%lf",&x);
printf("sin(%lf)=%lf\n",x,sin(x));
return 0;
}
double sin(double x)
{
int i=0;
double result=0,n=0;
while( fabs( n=nResult(x,2*++i-1) ) > 0e-7 )
result+=(i%2==1)?n:-n;
return result;
}
double nResult(double x,double n)
{
return n==1?x:nResult(x,n-1)*x/n;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-10644d08b6d742ccaab5c3ce5529d169",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "8768e1f7de284b05abb9723b43cac495",
"keywords": "算法高阶,NP完全性,算法问题选编,多项式时间的验证"
}
\ No newline at end of file
# 猴子吃桃
问题:猴子第一天摘了若干个桃子,吃了一半,不过瘾,又多吃了1个。第二天早上将剩余的桃子又吃掉一半,并且又多吃了1个。此后每天都是吃掉前一天剩下的一半零一个。到第n天再想吃时,发现只剩下1个桃子,问第一天它摘了多少桃子?为了加强交互性,由用户输入不同的天数n进行递推,即假设第n天的桃子数为1。同时还要增加对用户输入数据的合法性验证(如:不允许输入的天数是0和负数)
## template
```cpp
#include <stdio.h>
int main()
{
int ret,day,i=1,sum=1;
while (1)
{
printf("Input days:\n");
ret=scanf("%d",&day);
if ((ret!=1)||(day<=0))
{
fflush(stdin);
continue;
}
break;
}
do
{
sum=(sum+1)*2;
i++;
}while(i<day);
printf("sum=%d\n",sum);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a3eea22959d94e099f45b0ac75182455",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "589b231575924a8da40c995de5f96f5f",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 利用字母组成图形
利用字母可以组成一些美丽的图形,下面给出了一个例子:
ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC
这是一个5行7列的图形,请找出这个图形的规律,并输出一个n行m列的图形。
输入一行,包含两个整数n和m,分别表示你要输出的图形的行数的列数。
## template
```cpp
#include<stdio.h>
#include<math.h>
int main()
{
int m,n;
scanf("%d%d",&n,&m);
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%c",65+abs(i-j));
}
printf("\n");
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-2d0380306f4e47c7b59898609265514e",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "6e1c95850ac94132a689c787d6a2a0e6",
"keywords": "算法高阶,数论算法,元素的幂,算法问题选编"
}
\ No newline at end of file
# 输入一个数查找比它小的元素
<p>一个整型数组有10元素&#xff0c;请先给这10个元素赋值&#xff0c;然后随便输入一个数&#xff0c;最后输出数组中比这个数小的所有元素&#xff0c;每个数用空格隔开&#xff0c;如果没有找到&#xff0c;则输出not find。<br />
 </p>
<p style="text-align:center"><img alt="" src="https://img-ask.csdnimg.cn/upload/1624519041254.jpg" />
 </p>
## template
```cpp
#include <stdio.h>
int main()
{
int a[10],i,n;
int isfind = 0;
printf("please set array values:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("please enter one num:");
scanf("%d",&n);
for (i=0;i<10;i++)
{
if(a[i] < n)
{
isfind = 1;
printf("%d ",a[i]);
}
}
if(isfind)
printf("\n");
else
printf("not find\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-f0e4e84c8c5f4399b7ed5e6faced7c8d",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "e72e35038ad34d3e9ecdddb5b978d68b",
"keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量"
}
\ No newline at end of file
# 二维数组找最值
<pre><p>从键盘输入m(2&lt;&#61;m&lt;&#61;6)行n(2&lt;&#61;n&lt;&#61;6)列整型数据&#xff0c;编程找出其中的最大值及其所在位置的行列下标值并输出。
输入格式:
在第一行输入数据的行数m和列数n的值&#xff0c;从第二行开始以二维数组的形式依次输入m行n列整型数据。
输出格式:
依次输出最大值及其所在位置的行列下标值&#xff0c;中间以逗号,分隔&#xff0c;最后换行。
</pre>输入样例:</p>
<pre>
<code>3 4
1 2 3 4
8 9 7 6
5 6 7 0</code></pre>
<p>输出样例:</p>
<pre>
<code>9,1,1</code></pre>
## template
```cpp
#include <stdio.h>
int main ()
{
int a[6][6];
int m,n;
int i,j;
int max;
int indexx=0,indexy=0;
scanf("%d %d",&m,&n);
for (i = 0;i<m;i++)
{
for (j = 0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(i == 0 && j==0)
{
max = a[i][j];
indexx = 0;
indexy = 0;
}else
{
if (a[i][j] > max)
{
max = a[i][j];
indexx = i;
indexy = j;
}
}
}
}
printf("%d,%d,%d\n",max,indexx,indexy);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-8a0f60c168fa499d8174ff503465e94c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "08767f755b5a4ad7a70b596083a8a7a3",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 已知一个浮点数A(0<A<5),求它由哪两个整数B/C相除的值最接近
已知一个浮点数A(0<A<5),求它由哪两个整数B/C相除的值最接近,有相同值时要求B最小
例如:
A=0.2
B=1 C=5
## template
```cpp
#include <stdio.h>
#include <math.h>
int main () {
float A = 0.2f;
int x = 0;
if (A < 0) { x = 1; A = 1/A; }
float delta = 1;
int B = 1, C = 1;
do
{
C = (int)(B * A);
delta = fabs(C/(float)B-A);
B++;
}
while (delta > 0.000001);
if (x == 0)
printf("%d / %d", C, B - 1);
else
printf("%d / %d", B - 1, C);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-94cf764cfc9240878c1ef177879b0d05",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c1ccba772e2f4fa0b660596dd9873db8",
"keywords": "算法初阶,基础知识,分治策略,证明主定理,对b的幂证明主定理"
}
\ No newline at end of file
# 矩阵问题
题目描述
编写以下函数:
(1)在一个二维数组中形成以下形式的n阶矩阵:
[1 1 1 1 1
2 1 1 1 1
3 2 1 1 1
4 3 2 1 1
5 4 3 2 1]
(2)去掉靠边的元素,生成新的n-2阶矩阵;
(3)求生成的n阶矩阵主对角线上的元素之和;
(4)以方阵形式输出数组。
在main函数中调用以上函数进行测试。
输入
输入生成矩阵的阶数(n>=2)
输出
以方阵形式输出生成的n阶矩阵、去掉靠边的元素生成的新的n-2阶矩阵、以及生成的n阶矩阵主对角线上的元素之和,最后一行要回车
样例输入
5
样例输出
Generated matrix:
1 1 1 1 1
2 1 1 1 1
3 2 1 1 1
4 3 2 1 1
5 4 3 2 1
del the elements on the side:
1 1 1
2 1 1
3 2 1
The sum of the diagonal:5
## template
```cpp
#include <iostream>
using namespace std;
int main() {
while(1){
int a;
cin>>a;
int array[a][a];
for (int i=0;i<a;i++)
for (int j=0;j<a;j++)
{
if(j<i)
array[i][j]=i+1-j;
else
array[i][j]=1;
}
cout<<"Generated matrix:"<<endl;
for (int i=0;i<a;i++)
{
for (int j=0;j<a;j++)
{
cout<<array[i][j];
}
cout<<endl;
}
cout<<"del the elements on the side:"<<endl;
for (int i=1;i<a-1;i++)
{
for (int j=1;j<a-1;j++)
{
cout<<array[i][j];
}
cout<<endl;
}
int sum=0;
int i,j;
for (i = a - 2 ,j = 1 ; i >= 1 ; i-- , j++)
{
sum+=array[i][j];
}
cout<<"The sum of the diagonal:"<<sum<<endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-fd15f4833f2243e097fc1186e054ac0c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "36320ab5d7c84622a65d9749ad231d17",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量,期望为线性时间的选择算法"
}
\ No newline at end of file
# 偶数 or 奇数
偶数 or 奇数
时间限制: 1 Sec 内存限制: 128 MB
题目描述
编程班老师搞了一个有 N (1 <= N <= 100) 个正整数 I (1 <= I <= 10^60) 的表,叫 同学们去统计每个数里面数字(0,1,2,3,4,5,6,7,8,9)(注 0 为偶数)的奇偶数 字个数。写一个程序读入 N 个整数,统计每个整数的数字奇偶个数。
输入
第 1 行: 一个单独的整数: N
第 2 到第 N+1 行: 每行一个长长(小于等于 60 位)的整数,需要统计数字奇偶个数。
输出
1..N 行: 第 j 行根据第 j 个整数输出奇数个数与偶数个数。
样例输入
2
1024
5931
样例输出
1 3
4 0
## template
```cpp
#include<iostream>
#include<string>
using namespace std;
string a[105];
int b[105],c[105];
int qiujishu(string x){
int jishu=0;
for(int i = 0; x.c_str()[i]; i++){
if ((x.c_str()[i] - '0') % 2 == 1) jishu++;
}
return jishu;
}
int qiuoushu(string x){
int oushu=0;
for(int i = 0; x.c_str()[i]; i++){
if ((x.c_str()[i] - '0') % 2 == 0) oushu++;
}
return oushu;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=qiujishu(a[i]);
c[i]=qiuoushu(a[i]);
}
for(int i=1;i<=n;i++){
cout<<b[i]<<" "<<c[i]<<endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a111c5c33edb4c42ab690597a4e47379",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "5a82d65c1e2848299ac763483c711ab1",
"keywords": "图算法,算法高阶,图的表示,基本的图算法"
}
\ No newline at end of file
# 卖树苗
<pre><p>题目描述
植树节又到了,商家A和商家B为了卖出更多的树苗。<br />
商家A有了新的决定&#xff1a;<br />
购买树苗数量小于等于10棵&#xff0c;所有树苗按正常价格10元一棵收费&#xff1b;<br />
购买树苗数量大于10且小于等于20棵&#xff0c;超出10棵以上的树苗按8.2元一棵收费&#xff0c;其余树苗按正常价格收费&#xff1b;<br />
购买树苗数量大于20棵&#xff0c;超出20棵以上的树苗按7.5元一棵收费&#xff0c;10至20棵部分树苗按8.2元一棵收费&#xff0c;其余树苗按正常价格收费。<br />
商家B决定&#xff1a;<br />
所有树苗12元一棵&#xff0c;但是均打七折卖出。</pre><pre>图图要代表班级去买树苗&#xff0c;要求输入图图需要购买的树苗棵数&#xff0c;输出在哪家商家购买更加划算及其所要花费的钱数。
输入要求
1 行,一个整数&#xff0c;表示图图需要购买的树苗数量。
输出要求
1 行,如果商家A的树苗比较划算&#xff0c;输出&#xff1a;A&#xff0c;否则输出&#xff1a;B&#xff0c;同时输出图图购买树苗最优惠的钱数&#xff08;文字和数字间用空格隔开&#xff09;</pre>
样例输入 </p>
<pre>
30</pre>
<p>样例输出 </p>
<pre>
B 252</pre>
## template
```cpp
#include <iostream>
using namespace std;
int main() {
double n, A, B;
cin >> n;
B = 12 * 0.7 * n;
if (n <= 10) {
A = 10 * n;
}
else if (n > 10 && n <= 20) {
A = 10 * 10 + (n - 10) * 8.2;
}
else {
A = 10 * 8.2 + (n - 20) * 7.5 + 10 * 10;
}
if (A < B) {
cout << "A " << A;
}
else {
cout << "B " << B;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-04b61ba3ff344d4392bcb2294230a449",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "05e05c3ea3db434da77e0f5dc0096a15",
"keywords": "算法高阶,多线程算法,算法问题选编,动态多线程基础"
}
\ No newline at end of file
# 多线程问题
1.程序中需要开启两个线程(线程1和线程2)
2.线程1固定5秒钟执行一次
3.线程2固定10秒钟执行一次
4.开启程序如何做到线程1执行完成后再执行线程2并且在之后无论谁先执行都需等待对方执行完成后才可以开始执行
## template
```java
public class TestThreadJoin {
public static void main(String[] args) {
final Object lock = new Object();
Runnable r1 = () -> {
while (true) {
synchronized (lock) {
System.out.println("线程1执行。");
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Runnable r2 = () -> {
while (true) {
synchronized (lock) {
System.out.println("线程2执行。");
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
new Thread(r1).start();
new Thread(r2).start();
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-8f89b405b7cf45ceb207696935617878",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "50ed3bc1755a48ffa7016241abcf2909",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量,最坏情况为线性时间的选择算法"
}
\ No newline at end of file
# 外出采摘的日本人
二战后的某一天,N个日本人来到了一个山洞休息,为了派出一个日本人去外面充满危险的丛林中采摘食物,他们设置如下游戏产生外出采摘的人:
1、首先,所有参加游戏的日本人按顺序编号为1、2、3…N;
2、接下来每个日本人心里产生一个数字,这个数字称为序号为 N的人的密码P;
3、所有参加游戏的人按照编号站成一个圈,长老为游戏设置初始密码K,从编号为 1的人开始报数,报到 K的人退出队伍,然后将自己心中的密码P说出来,由下一个人继续从 1开始报数,报到P的人退出队伍,以此类推;
4、当队伍中剩下一个人的时候,这个人就是今天要出去采摘的日本人,他可能回不来了!
请各位同学设计程序并使用Java语言实现改程序,在用户输入了人数N、每个人的密码P和初始密码K的情况下,自动完成上面的选择过程,输出先后离开队伍的人的序号序列,最后输出要去采摘的日本人,输出他的编号。
## template
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class JosephCircle {
public int newJoseph(int n, int[] p, int k) {
List<Integer> num = new ArrayList<Integer>();
for (int i = 0; i < n; i++)
num.add(i);
int t = k, index = 0;
for (int i = 0; i < n - 1; i++) {
index = (index + t) % num.size();
num.remove(index);
t = p[index];
if (index == num.size())
index = 0;
}
return num.get(0) + 1;
}
public int oldJoseph(int n, int k) {
int w = 0;
for (int i = 2; i <= n; i++) {
w = (w + k) % i;
}
return w;
}
public static void main(String[] args) {
JosephCircle jc = new JosephCircle();
Scanner scan = new Scanner(System.in);
int n, k;
int[] p = new int[100];
System.out.print("Enter N = ");
n = scan.nextInt();
System.out.print("Enter P[] = ");
for (int i = 0; i < n; i++) {
p[i] = scan.nextInt();
}
System.out.print("Enter K = ");
k = scan.nextInt();
System.out.println();
System.out.println("Survivor is No." + jc.newJoseph(n, p, k));
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-53d5b98ae032471dbe54cbd6b124e066",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "7ed8042a4c154c33aa6d2e7916925f51",
"keywords": "算法高阶,数论算法,素数的测试,算法问题选编"
}
\ No newline at end of file
# 求素数和
求第m个到第n个素数之间的素数和
## template
```java
import java.util.Scanner;
public class All {
public static void main(String[] args) {
int a[] = new int[200];
int index = 0;
for (int i = 1; i < 200; i++) {
boolean isPrime = true;
for (int k = 2; k < i; k++) {
if (i % k == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
a[index++] = i;
System.out.println(a[index - 1]);
}
}
Scanner small = new Scanner(System.in);
Scanner large = new Scanner(System.in);
int m = small.nextInt();
int n = large.nextInt();
int sums = 0;
int suml = 0;
int sum = 0;
for (int i = 0; i < m; i++) {
sums += a[i];
System.out.print(a[i] + "*");
}
for (int i = 0; i < n; i++) {
suml += a[i];
System.out.print(a[i] + " ");
}
sum = suml - sums;
System.out.println(sum);
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-10bdf8e112564ababe1b686b26af3a13",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "272e224c4e9a4efa84fa5b9bd2bb502b",
"keywords": "算法"
}
\ No newline at end of file
# 发奖金问题
过年了,村里要庆祝。村长说,村里有一笔钱作为奖金,让每个人写一个纸条上来,谁写的数目与奖金最接近,就算猜中,这笔奖金就归谁,如果多人猜中,则平分。编写程序,算算都有哪些人得到奖金?多少?
## template
```java
import java.util.Collections;
import java.util.Comparator;
import java.util.Arrays;
class Q707984 {
public static void main(String[] args) {
int award = 100;
String[] people = { "a", "b", "c", "d", "e", "f", "g", "h" };
Integer[] guess = { 75, 70, 80, 120, 100, 110, 100, 45 };
Integer[] ordered = new Integer[people.length];
for (int i = 0; i < ordered.length; i++)
ordered[i] = i;
Arrays.sort(ordered, new Comparator<Integer>() {
@Override
public int compare(Integer a, Integer b) {
int x = guess[a] - award > 0 ? guess[a] - award : award - guess[a];
int y = guess[b] - award > 0 ? guess[b] - award : award - guess[b];
return x - y;
}
});
int maxp = 0;
int i = 0;
while (guess[ordered[i++]] == award)
maxp++;
if (maxp <= 1)
System.out.println(people[ordered[0]] + "一人得奖" + award + "元。");
else {
for (i = 0; i < maxp; i++)
System.out.print(people[ordered[i]] + " ");
System.out.println("共同得奖" + award / (float) (maxp) + "元。");
}
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-01b8a7eb15a2496b8e748cf4df9d8e3a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ea3dd807e4084c1986e96fc31d70def9",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 单词反转
随便输出一个字符串
String str ="45abc,+de==fg";
里面含有 abc,de,fg 三个单词
怎么处理能让单词反转,其他顺序不变呢
输出 “45cba,+ed==gf”;
## template
```java
public class HelloWorld {
public static String revstr(String s) {
char[] ch = s.toCharArray();
for (int i = 0; i < ch.length; i++) {
if ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')) {
int j = i + 1;
while (j < ch.length && ((ch[j] >= 'A' && ch[j] <= 'Z') || (ch[j] >= 'a' && ch[j] <= 'z')))
j++;
j--;
if (i != j) {
for (int k = i; k <= (j - i) / 2 + i; k++) {
char temp = ch[k];
ch[k] = ch[j - k + i];
ch[j - k + i] = temp;
}
}
i = j;
}
}
return new String(ch);
}
public static void main(String[] args) {
System.out.println(revstr("45abc,+de==fg"));
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```
\ No newline at end of file
{
"node_id": "dailycode-f08326c0d02e484b9f6f409eac8b0d3f",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "53ff0ec21c6f499b8dc270dcbc9d3d9c",
"keywords": "算法初阶,基础知识,算法基础,设计算法,分析分治算法"
}
\ No newline at end of file
# 将一组数尽可能均匀地分成两堆,使两个堆中的数的和尽可能相等
<p>麦克叔叔去世了,他在遗嘱中给他的两个孙子阿贝和鲍勃留下了一堆珍贵的口袋妖怪卡片。遗嘱中唯一的方向是“尽可能均匀地分配纸牌的价值”。作为Mike遗嘱的执行人,你已经为每一张口袋妖怪卡片定价,以获得准确的货币价值。你要决定如何将口袋妖怪卡片分成两堆,以尽量减少每一堆卡片的价值总和的差异。
例如,你有下列n=8 个口袋妖怪卡片:
![图片说明](https://img-ask.csdn.net/upload/202006/27/1593264517_917706.png)
经过大量的工作,你发现你可以用下面的方法来划分卡片:
![图片说明](https://img-ask.csdn.net/upload/202006/27/1593264556_309804.png)
这给了安倍10美元的牌给了鲍勃11美元的牌。这是最好的除法吗?
你要做的是解决n张牌的问题其中每张牌ci都有一个正整数值vi.你的解决方法是计算牌应该如何被分割以及每摞牌的价值。
输入输出示例如下:
![图片说明](https://img-ask.csdn.net/upload/202006/27/1593264585_763892.png)
1.通过检查所有可能的桩以蛮力解决此问题。 对这种蛮力算法的时间复杂度进行分析,并通过实施和实验验证您的分析结果(既写出来算法的设计思路等),并用python算法实现编程
2.通过动态编程开发更有效的算法。 您应该首先通过动态编程的思想来分析此问题,并编写相应的递归属性。 对这种算法的时间复杂度进行分析,并通过实施和实验验证您的分析结果。并用python代码实现动态编程</p>
## template
```python
def deal(data,flag):
a=[]
for i in data:
if i>=flag:
return [i]
elif a==[]:
a.append([i])
else:
a=a+[k+[i] for k in a if sum(k)+i<=flag]
a.append([i])
target=sum(max(a,key=sum))
return list(filter(lambda x:sum(x)==target,a))
if __name__=='__main__':
c=[2,1,3,1,5,2,3,4]
flag=sum(c)//2
res=deal(c,flag)
print(res)
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-86c49baf0f2e4bf684259a6a1cfb4e9b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "6d55095b9cbe489f83e68c2dec32c775",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 求两个给定正整数的最大公约数和最小公倍数
<pre><p>本题要求两个给定正整数的最大公约数和最小公倍数。
输入格式:
输入在两行中分别输入正整数x和y。
输出格式:
在一行中输出最大公约数和最小公倍数的值。
</pre><pre>输入样例1:
在这里给出一组输入。
例如&#xff1a;</p><pre><code>100
1520</code></pre><p>输出样例1:
在这里给出相应的输出。
例如&#xff1a;</p><pre><code>20 7600</code></pre></pre>
## template
```python
def hcf(x, y):
if x > y:
smaller = y
else:
smaller = x
for i in range(1,smaller + 1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = int(input("输入第一个数字: "))
num2 = int(input("输入第二个数字: "))
print("最大公约数为",hcf(num1, num2),"最小公倍数为",lcm(num1,num2))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-2a95d4b9b0184d158ce266e264f3aa89",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4bf93e34b35444508093411478f31065",
"keywords": "数学,算法"
}
\ No newline at end of file
# 实现保留3位有效数字(四舍六入五成双规则)
输入:1234 输出:1234
12 12.0
4 4.00
0.2 0.200
0.32 0.320
1.3 1.30
1.235 1.24
1.245 1.24
1.2451 1.25
## template
```python
a = input()
if '.' in a:
a = float(a)
if a*1000%10!=5:
a = '%.2f'%(a)
else:
if len(str(a).split(".")[1])>3:
a = '%.2f'%(a)
else:
if int(a*100%10%2)==1:
a = float('%.2f'%float(int(a*100)/100))+0.01
else:
a = '%.2f'%float(int(a*100)/100)
print(a)
else:
a = int(a)
if a>99:
print(a)
else:
if 0 < a < 10:
print('%.2f'%a)
else:
print(float(a))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-6ea0e4fb8629442784f597db57cd002c",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "65db405fe5a5454fbbede206bf48975c",
"keywords": "散列表,散列表,算法中阶,数据结构"
}
\ No newline at end of file
# 求列表(整数列表)的平衡点
对于一个整数列表,如果有一个切分位置使其前面的元素之和等于后面的元素之和,就称该位置是平衡点
请编写程序求列表(整数列表)的平衡点,不存在时给出提示。
思路:
1.确定一个位置
2.求在这个位置前面的元素之和,与在这个位置后面的元素之和,做比较,判断是否相等
2.1 怎么求前面元素之和:
假设这个位置是[i],那么前面元素就是[0]~[i-1], 后面元素为[i+1]~[len(list)-1]
进行求和:累加求和
2.2判断是否相等:相等,给出这个平衡位置;不相等,输出“该列表不存在平衡点”
## template
```python
a=input('请输入一个整数列表:').split(",")
flag=0
for i in range(0,len(a)-1):
s1=0
for m in range(0,i):
s1+=int(a[m])
s2=0
for n in range(i+1,len(a)):
s2+=int(a[n])
if s1==s2:
print('该整数列表存在平衡点,且平衡点为:',a[i])
flag=1
break
if flag==0:
print('该整数列表不存在平衡点')
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
{
"node_id": "dailycode-c893ed3e15914f5eb14ba69dcc053269",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2d6d0c5800234db482a8a30a4c764d23",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 最小花费
<p>题目描述</p><p style="margin-left:0; margin-right:0">乐乐做好了一二三等奖奖品费用预算方案之后&#xff0c;决定到市场上具体咨询一下三种奖品的具体价格&#xff0c;发现各个商家的报价还是有差别的&#xff0c;乐乐决定哪家所有奖品总金额最少就在哪家购买&#xff0c;假设每家货源是充足的。乐乐咨询了n个店家&#xff0c;几乎跑遍了整个市场&#xff0c;才得到各个商家的最低报价清单。现在请你计算出乐乐会在哪家商家购买奖品以及费用是多少。
输入</p><p style="margin-left:0; margin-right:0">共 n&#43;1 行 </p><p style="margin-left:0; margin-right:0">第一行&#xff0c;有四个整数 n,x,y,z&#xff0c;数与数之间用一个空格隔开&#xff0c;n 表示乐乐咨询的商家数&#xff0c;x,y,z 分别表示要购买一等奖奖品数量、二等奖奖品数量、三等奖奖品数量。 </p><p style="margin-left:0; margin-right:0">接下来的 n 行&#xff0c;每行都有三个数&#xff0c;数与数之间用一个空格隔开&#xff0c;第 i&#43;1 行分别表示编号为 i 的商家对一、二、三等奖奖品的报价&#xff08;单价&#xff09; 
输出</p><p style="margin-left:0; margin-right:0">共有两个整数&#xff0c;第一个数表示购买奖品的商家编号&#xff08;如果有多家总费用最少&#xff0c;输出编号最小的商家&#xff09;&#xff0c;第二个数是购买奖品的总费用。 
样例输入</p><pre class="has" style="margin-left:0; margin-right:0">
<code class="language-content">3 1 2 3
70 50 30
60 40 20
80 55 33
</code></pre><p>样例输出</p><pre class="has" style="margin-left:0; margin-right:0">
<code class="language-content">2 200</code></pre><p>提示</p><p style="margin-left:0; margin-right:0">【样例解释】</p><p style="margin-left:-0.5pt; margin-right:0">乐乐咨询了 3 个商家&#xff0c;打算购买一二三等奖奖品数量分别是 1 个、2 个、3 个&#xff0c;编号为 1 的商家一二三等奖奖品报价分别是 70、50、30 元&#xff0c;编号为 2 的商家报价分别是 60、40、20 元&#xff0c;编号为 3 的商家报价分别是 80、55、20 元&#xff0c;乐乐在编号为 2 的商家购买总费用最低&#xff0c;为200 元。</p><p style="margin-left:0; margin-right:0">【数据范围】</p><p style="margin-left:23.75pt; margin-right:0">40%数据&#xff1a;1≤n≤5000 </p><p style="margin-left:23.75pt; margin-right:0">100%数据&#xff1a;1≤n≤100000&#xff0c;1≤x,y,z≤1000&#xff0c;奖品报价都是 1000 范围以内的正整数。</p>
## template
```cpp
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int n,x,y,z,i,min=1000000,n1,n2,n3,temp,t=0;
cin>>n>>x>>y>>z;
for(i=0;i<n;i++){
temp=0;
cin>>n1>>n2>>n3;
temp+=n1*x+n2*y+n3*z;
if(temp<min){
min=temp;
t=i+1;
}
}
cout<<t<<" "<<min;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4ba7db9d26f146d5ab2e623bb4ea523d",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "48c6719fb7334a32a1f1508c83d4c7e1",
"keywords": "算法中阶,动态规划,动态规划原理,高级设计和分析技术"
}
\ No newline at end of file
# 动态规划-硬币重量最轻问题
<p>设有n种不同面值的硬币&#xff0c;第i种硬币的币值是Vi(其中V1&#61;1),重量是Wi,i&#61;1,2&#xff0c;...n且现在购买某种总币值为y的商品&#xff0c;需要用这些硬币付款&#xff0c;如果每种钱币使用的个数不限&#xff0c;那么如何选择付款的方法使得付出钱币的总重量最轻&#xff1f;使用动态规划设计策略设计一个求解该问题的算法。假设问题的输入实例是&#xff1a;</p><p style="margin-left:.38in">V1&#61;1&#xff0c; V2&#61;4&#xff0c; V3&#61;6&#xff0c; V4&#61;8</p><p style="margin-left:.38in">W1&#61;1&#xff0c; W2&#61;2&#xff0c;W3&#61;4&#xff0c;W4&#61;6</p><p style="margin-left:.38in">Y&#61;12</p><p>要求输出优化函数表和标记函数表、以及硬币支付方式。</p>
## template
```cpp
#include<stdio.h>
void strcpy(int *a, int *b, int Y){
for(int i=0;i<=Y;i++) *(a+i) = *(b+i);
}
void solve(){
int n; scanf("%d",&n);
int type[n], weight[n], Y, i, j, k;
for(i=0;i<n;i++) scanf("%d",&type[i]);
for(i=0;i<n;i++) scanf("%d",&weight[i]);
scanf("%d",&Y);
int Min[Y+1], Min_Path[Y+1], path[n][Y+1];
for(i=0;i<=Y;i++) Min[i] = 9999;
Min[0] = 0;
printf("\n");
for(j=0;j<n;j++){
for(i=type[j]; i<=Y; i++)
if(Min[i] > Min[i-type[j]]+weight[j]){
Min_Path[i] = type[j];
Min[i] = Min[i-type[j]]+weight[j];
}
for(k=1;k<=Y;k++) printf("%-3d",Min[k]);
printf("\n");
strcpy(path[j],Min_Path,Y);
}
printf("\n");
for(i=0;i<n;i++){
for(j=1;j<=Y;j++)
printf("%-3d",path[i][j]);
printf("\n");
}
int y=Y;
printf("\n支付方式:");
while (y){
printf("%d ",Min_Path[y]);
y -= Min_Path[y];
}
printf("\n总重量:%d\n",Min[Y]);
}
int main(){
solve();
return 1;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-01d0ed21586140bc95fa7ca76dc1fed9",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "02b466beab4a439bbd3ac7248556570c",
"keywords": "算法初阶,基础知识,分治策略,最大子数组问题"
}
\ No newline at end of file
# 找x
题目描述
输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。
输入
测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。
输出
对于每组输入,请输出结果。
样例输入
4
1 2 3 4
3
样例输出
2
## template
```cpp
#include <iostream>
using namespace std;
int main() {
int n = 0;
cin >> n;
int* ptr = new(nothrow) int[n];
for (auto i = 0; i < n; i++) {
cin >> ptr[i];
}
int x = 0;
cin >> x;
auto j = 0;
auto status = 0;
for (; j < n; ++j) {
if (ptr[j] == x) {
status = 1;
break;
}
}
if (status == 0) {
j = -1;
}
cout << j << endl;
delete[] ptr;
cin.get();
cin.get();
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-f891ffda091f47ec800fa6bf9218dcf9",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "33d1db9098d74f758cc502437301c204",
"keywords": "算法初阶,快速排序,快速排序分析,期望运行时间,排序和顺序统计量"
}
\ No newline at end of file
# 可怕的流感
<p style="margin-left:0pt; margin-right:0pt">Ø 问题描述&#xff1a;已知一只家禽得了流感&#xff0c;流感的传播时间为 24 小时&#xff0c;在这 24 小时内最多能将流感传给其它 M 只家禽&#xff0c;农场主需要购买紧急药品&#xff0c;假设发现时已经过了 N 天&#xff0c;那么农场主需要至少买多少包药呢&#xff1f;&#xff08;一包药为一只家禽用量&#xff09;</p><p style="margin-left:0pt; margin-right:0pt">Ø 输入&#xff1a;一行&#xff0c;两个整数&#xff0c;第一个表示流感传染家禽的数量 M&#xff0c;第二个表示发现时已过的天数。</p><p style="margin-left:0pt; margin-right:0pt">Ø 输出&#xff1a;一行&#xff0c;一个整数&#xff0c;表示需要药的包数。</p><p style="margin-left:0pt; margin-right:0pt">Ø 样例输入&#xff1a;</p><p style="margin-left:0pt; margin-right:0pt">10 2</p><p style="margin-left:0pt; margin-right:0pt">Ø 样例输出&#xff1a;</p><p style="margin-left:0pt; margin-right:0pt">121</p>
## template
```cpp
#include <iostream>
using namespace std;
int total(int x);
int m;
int main() {
int x;
cin >> m >> x;
int to = total(x);
cout << to;
return 0;
}
int total(int x) {
if (x > 0)
{
return (m + 1) * total(x - 1);
}
else return 1;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-daa69616a1814fb8a17dcebd6650f769",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "17ea742acdc54c1fb34ad7985257d2a6",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 优雅的字符串
<p>对于一个字符串&#xff0c;如果这个字符串在ASCII码的意义上是有序的&#xff0c;即升序或降序&#xff0c;则称该字符串为“优雅的字符串”。一个长为n的字符串s&#xff0c;对于1&lt;&#61; i &lt;&#61; n - 1&#xff0c;如果总有s[i] &lt;&#61; s[i&#43;1]&#xff0c;则字符串为升序&#xff1b;如果总有s[i] &gt;&#61; s[i&#43;1]&#xff0c;则字符串降序。现给定一个字符串&#xff0c;请你判断该字符串是否“优雅”&#xff0c;如果该字符串是“优雅”的&#xff0c;则判断是“正优雅”&#xff08;升序&#xff09;还是“负优雅”&#xff08;降序&#xff09;
输入描述
一个非空&#xff0c;不包含空格的字符串s&#xff0c;保证字符串中的字符都是ASCII标准中的字符。数据保证不会出现所有字符相同的字符串。&#xff08;2&lt;&#61; length(s) &lt;&#61;1e5&#xff09;
输出描述
如果字符串“正优雅”&#xff0c;则输出“Positive elegance”&#xff0c;如果“负优雅”&#xff0c;则输出“Negative elegance”&#xff0c;否则输出“Non elegance”&#xff08;均不含引号&#xff09;
样例输入 (*&#43;12356ASdfz
样例输出
Positive elegance</p>
## template
```cpp
#include <stdio.h>
#include <string.h>
int main()
{
char a[100] = {0};
int i;
int zyy = 1;
int fyy = 1;
printf("请输入字符串:");
gets(a);
for (i=1;i<strlen(a);i++)
{
if(a[i] < a[i-1])
{
zyy = 0;
break;
}
}
for (i=1;i<strlen(a);i++)
{
if(a[i] > a[i-1])
{
fyy = 0;
break;
}
}
if (zyy && !fyy)
{
printf("Positive elegance\n");
}else if (!zyy && fyy)
{
printf("Negative elegance\n");
}else
printf("Non elegance\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-7c18a36a13c64cada980065407113c6f",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "c0dae346f2824faaa512389cbdd8e2ec",
"keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术"
}
\ No newline at end of file
# 蓝桥杯Candy Store
<p>问题描述
经营一家糖果店是非常困难的&#xff0c;你需要优化各种各样的东西。最近你在销售一种非常时髦的糖果&#xff0c;叫做Whizboppers。这种糖果变质非常迅速&#xff0c;所以&#xff1a;<br />
  ·你必须每天早上从供应商买来新的Whizboppers。<br />
  ·你必须用当天早上从供应商买来的盒子装着糖果出售。<br />
  你可以从你的供应商处买来装有任意整数克糖果的盒子。<br />
  每天有至多k位顾客到你的店里来。从第1个人开始&#xff0c;每个人会选择花费整数分的钱来买Whizboppers&#xff0c;钱数在1分到C分之间&#xff08;包含1分和C分&#xff09;。你打算以1分钱每克的价格出售&#xff1b;所以如果一个人想要花4分钱&#xff0c;你会给他恰好4克糖果。你可以给他1个4克的盒子&#xff0c;也可能是1个2克的盒子和2个1克的盒子。<br />
  你最少需要买几个盒子才能保证&#xff0c;不管每个人想花多少钱买糖&#xff0c;你总是可以给他们对应质量的糖果&#xff1f;
<br />  注意&#xff1a;当一个人选择自己想买多少糖果后&#xff0c;你知道之前的人已经买了多少糖&#xff0c;但不能预知之后的人打算买多少糖。<br />
  举个例子&#xff0c;如果每天至多有2位顾客到你的店里&#xff0c;每个人至多花2分钱(k&#61;2,C&#61;2)&#xff0c;你可以从你的供应商买4个1克的盒子。但是你可以做的更好&#xff1a;只要买2个1克的盒子和1个2克的盒子&#xff0c;就可以满足你的顾客。如下所示&#xff1a;<br />
第一个人给第一个人的盒子第二个人给第二个人的盒子2分1 个 2克2分<br />
1分2 个 1克<br />
1 个 1克1分1 个 1克2分<br />
1分1 个 2克<br />
1 个 1克<br />  不论第一个人怎么买&#xff0c;你都可以给他对应质量的盒子&#xff0c;同时保证第二个人也能拿到正确质量的糖果。所以对于k&#61;2,C&#61;2&#xff0c;你用3个盒子就可以满足任意的顾客需求。
输入格式
  第一行一个整数T&#xff0c;表示询问数量。
  接下来T行&#xff0c;每行包含两个整数k和C&#xff0c;分别表示最大人数和每个人花费的最多钱数。
输出格式
  对于每一个询问&#xff0c;输出一行包含&#34;Case #x: y&#34;&#xff0c;x是询问编号&#xff08;从1开始标号&#xff09;&#xff0c;y是你每天最少需要的盒子数量。</p>
## template
```cpp
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n, k, count = 1;
long long c;
cin >> n;
while (n--)
{
cin >> k >> c;
int num = k;
long long sum = k;
for (long long i = 2; i <= c; i = sum / k + 1)
{
int t = num;
num += ceil((k * i - sum) * 1.0 / i);
sum += i * (num - t);
}
cout << "Case #" << count++ <<": " << num << endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-5e2efac0d42e482e8a0b8b447c0128ed",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "073181dd3e7e420391ee896ac800da03",
"keywords": "图算法,算法高阶,最小生成树,最小生成树的形成"
}
\ No newline at end of file
# 寻找孪生素数
数学家希尔伯特在1900年国际数学家大会的报告上提出一个“孪生素数猜想”,即: 存在无穷多个素数p,使得p + 2是素数。p和p+2这一对差为2的素数,被称为“孪生素数”。
看起来,这个猜想是成立的,我们总能找到很多对孪生素数,例如:3和5,5和7,11和13…… 这一猜想至今还未被证明。
现在,对于给定的整数n, 请寻找大于n的最小的一对孪生素数p和q(q=p+2)。
## template
```cpp
#include <cmath>
#include <iostream>
using namespace std;
int sushu(int x)
{
if (x <= 1) return 0;
int i,j=1;
for(i=2;i<=sqrt(x);i++)
{
if(x%i==0){j=0;break;}
}
return j;
}
int main()
{
int x;
cin>>x;
int i=x+1;
for(;;i++)
{
if (sushu(i)&&sushu(i+2))
break;
}
cout<<i<<' '<<i+2;
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-1537533abc064dfe94ebfa8dc8087b48",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ac3b91a2c31b4971a5cd238ae6519a85",
"keywords": "动态表,表扩张,算法中阶,摊还分析,高级设计和分析技术"
}
\ No newline at end of file
# 有序表的折半查找
问题描述:
用有序表表示静态查找表时,通常检索函数可以用折半查找来实现。
折半查找的查找过程是:首先确定待查记录所在的范围,然后逐步缩小范围直到找到或者确定找不到相应的记录为止。而每次需要缩小的范围均为上一次的一半,这样的查找过程可以被称为折半查找。
第二行包含n个用空格隔开的正整数,表示n个有序的整数。输入保证这n个整数是从小到大递增的。
第三行包含k个用空格隔开的正整数,表示k次查询的目标。
输出:
只有1行,包含k个整数,分别表示每一次的查询结果。如果在查询中找到了对应的整数,则输出其相应的位置,否则输出-1。
请在每个整数后输出一个空格,并请注意行尾输出换行。
## template
```cpp
#include <stdio.h>
int binary( int *a, int key, int n )
{
int left = 0, right = n - 1, mid = 0;
mid = ( left + right ) / 2;
while( left < right && a[mid] != key )
{
if( a[mid] < key )
left = mid + 1;
else if( a[mid] > key )
right = mid - 1;
mid = ( left + right ) / 2;
}
if( a[mid] == key ) return mid;
return -1;
}
int main (void)
{
int Base_a[20] = {1,3,5,8,9,40,120,123,125,150,199,200,1250,1255,1900,2000,2001,3000,3950,5000};
int Search_a[5] = {12,199,9,2001,3500};
int result = 0x00;
for(int i = 0;i < sizeof(Search_a)/sizeof(Search_a[0]);i++)
{
result = binary(Base_a,Search_a[i],sizeof(Base_a)/sizeof(Base_a[0]));
printf("[%d %d] ",Search_a[i],result);
}
printf("\n");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-11ca97b9b31d48f7a94f257b7b7a3189",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d428ae2f230b43b4a5166267a373b9e8",
"keywords": "图算法,算法高阶,图的表示,基本的图算法"
}
\ No newline at end of file
# 最优路线
题目描述
探险队要穿越泥潭,必须选择可踩踏的落脚点。可是泥潭面积很大,落脚点又实在少得可怜,一不小心就会深陷泥潭而无法脱身。侦查员费尽周折才从老乡手里弄到了一份地图,图中标出了落脚点的位置,而且令人震惊的是:泥潭只有一条穿越路线,且对于 n×m 的地图,路线长度为 n+m-1!请编程为探险队找出穿越路线。
输入描述
两个整数 n 和 m,表示泥潭的长和宽。下面 n 行 m 列表示地形(0 表示泥潭,1 表示落脚点)
输出描述
用坐标表示穿越路线,坐标之间用 > 分隔
样例输入
6 9
1 1 1 0 0 0 0 0 0
0 0 1 1 1 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 1 1 0 0 0
0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 1
样例输出
(1,1)>(1,2)>(1,3)>(2,3)>(2,4)>(2,5)>(3,5)>(4,5)>(4,6)>(5,6)>(5,7)>(5,8)>(5,9)>(6,9)
## template
```cpp
#include <stdio.h>
#include <string.h>
const int N=101;
int map[N][N];
int n,m;
struct point{
int l,r;
}node[N];
int ans;
void DFS(int x,int y)
{
if(x==n&&y==m)
{
for(int i=1;i<ans;i++)
printf("(%d,%d)>", node[i].l, node[i].r);
printf("(%d,%d)\n", x, y);
}
else{
if(map[x][y]==1&&x<=n&&y<=m)
{
node[ans].l=x;
node[ans].r=y;
ans++;
DFS(x+1,y);
DFS(x,y+1);
}
}
}
int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
ans=1;
memset(map,0,sizeof(map));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d", &map[i][j]);
DFS(1,1);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-37d86a8229ed48e386bd864651c96426",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "f190a78485c64ccfaca7cee8239f0ff3",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 指针排序问题
<p>输入10个数&#xff0c;按绝对值从大到小排序输出。
输入形式&#xff1a;输入10个float实数
输出形式&#xff1a;保留小数点后两位有效数字;输出从大到小排列
</p>
## template
```cpp
#include <math.h>
#include <stdio.h>
void paixu(float *p,int n)
{
int i,j;
for (i = 0; i<n-1; i++)
{
for (j = 0; j<n - 1 - i; j++)
{
if (fabs(p[j])<fabs(p[j + 1]))
{
float tmp;
tmp = p[j];
p[j] = p[j + 1];
p[j + 1] = tmp;
}
}
}
}
int main()
{
float f[10];
int i;
for(i=0;i<10;i++)
scanf("%f",&f[i]);
paixu(f,10);
for(i=0;i<10;i++)
printf("%.2f ",f[i]);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-eeef6cc975ee4b50a40ec3923a055d56",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "2bc817521b284d9b9ec532afdc2ca590",
"keywords": "算法初阶,基础知识,分治策略,用主方法求解递归式"
}
\ No newline at end of file
# 擅长编码的小k
题目描述
小k不仅擅长数学,也擅长编码。有一种编码方式如下:
首先写下文本中间的字符(如果文本中的字符编号为1..n,那么中间一个字符的编号为(n+1)DIV 2,其中DIV为整除的意思),然后 用这个方法递归地写下左边,最后再按这个方法递归地写下右边。例如,单词为orthography则其编码为gtorhoprahy。即先写中间的那个字符g,再对ortho递归地编码,最后将raphy递归地编码就得到了gtorhoprahy。
给一个原来的文本,求出编码后的 文本。
输入
一行字符,表示原始的文本内容。
输出
一行字符,表示编码后的文本内容。
样例
输入
orthography
输出
gtorhoprahy
提示
100%的数据,字符串长度不超过20000
## template
```cpp
#include <iostream>
#include <cstring>
using namespace std;
void shuchu(char *a,int m, int n)
{
if(n<=0||m<=0||m>n)
{
return;
}
else
{
cout << a[(m+n)/2];
shuchu(a,m,(m+n)/2-1);
shuchu(a,(m+n)/2+1,n);
}
}
int main()
{
char a[20000];
char b[20001];
cin >> a;
for(int i=0; i<20000; i++)
{
b[i+1] = a[i];
}
int n = strlen(a);
shuchu(b,1,n);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-41c67ea23bbd4b4db494db9e9c8ec713",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "8783f68a6359451182bb34824c538217",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 约瑟夫问题
<p>有n人&#xff08;编号分别为1到n号&#xff09;围成一圈&#xff0c;从第s人开始报数&#xff0c;报到第m的人出列&#xff0c;然后从出列的下一人重新开始报数&#xff0c;报到第m的人又出列&#xff0c;……&#xff0c;如此重复直到n-1全部出列&#xff0c;只剩最后一个人为止。求剩下的最后一人是谁&#xff1f;
输入
一行&#xff0c;三个整数n&#xff0c;m&#xff0c;s&#xff0c;&#xff08;0&lt;&#61;n&#xff0c;m&#xff0c;s&lt;&#61;1000&#xff09;意义如上。
输出
一行&#xff0c;一个正整数&#xff0c;表示最后剩下的人的编号。
输入样例</p>
<pre>
<code class="language-html">8 3 1</code></pre>
<p>输出样例</p>
<pre>
<code class="language-html">7</code>
</pre>
<p>要求从第s个数开始&#xff0c;数m个出列&#xff0c;第s个不出列</p>
## template
```cpp
#include <iostream>
void JosePhus(int n, int m, int start) {
    int i, *arr = new int[n];
    int count = 1;;
    for(i = 0;i < n; i++)
        arr[i] = i + 1;
    int sum = n;
    while(count < n) {
        start--;
        int index = (start+m-1) % sum;
        for(i = index; i < sum-1; i++)
            arr[i] = arr[i+1];
        start = index + 1;
        sum--;
        count++;
    }
    std::cout<< arr[0] <<"\n";
}
int main(int argc, const char * argv[]) {
    int n, m, start;
    std::cout << "请输入n,m,start:\n";
    while(std::cin >> n >> m >> start) {
        JosePhus(n, m, start);
        std::cout << "请输入n,m,start:\n";
    }
    return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-98d731ed290746578ffb4b32802a4d54",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4c53222ed7eb487391a899585069a437",
"keywords": "B树,算法高阶,高级数据结构,B树上的基本操作"
}
\ No newline at end of file
# 求解一元二次方程组根问题
<pre>利用公式x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b - sqrt(b*b-4*a*c))/(2*a)求一元二次方程ax<sup>2</sup> + bx + c =0 的根,其中a不等于0。
输入一行,包含三个浮点数a, b, c(它们之间以一个空格分开),分别表示方程ax<sup>2</sup> + bx + c =0 的系数。输出一行,表示方程的解。
若两个实根相等,则输出形式为:x1=x2=...。
若两个实根不等,则输出形式为:x1=...;x2 = ...,其中x1若是两个虚根,则输出:x1=实部+虚部i; x2=实部-虚部i,其中x1,x2满足以下两个条件中的一个:
1. x1的实部大于x2的实部
2. x1的实部等于x2的实部且x1的虚部大于等于x2的虚部
所有实数部分要求精确到小数点后5位,数字、符号之间没有空格。
样例输入:1.0 2.0 8.0
样例输出:x1=-1.00000+2.64575i;x2=-1.00000-2.64575i</pre>
## template
```cpp
#include <iostream>
#include<iomanip>
#include <cmath>
#include <complex>
using namespace std;
static const double e = 1e-12;
bool operator == (complex<double> c1, complex<double> c2) { return abs(c1-c2) < e;}
int main()
{
complex<double> a,b,c;
complex<double> x1,x2;
cin >> a >> b >> c;
x1 = (-b + sqrt(b*b-a*c*4.0))/(a*2.0);
x2 = (-b - sqrt(b*b-a*c*4.0))/(a*2.0);
cout << setiosflags(ios::fixed);
cout.precision(6);
if ( abs(x1.imag()) < e )
{
if (x1 == x2) {
cout << "x1=x2=" << x1.real();
} else {
cout << "x1=" << x1.real() <<";x2=" << x1.real();
}
}
else {
cout << "x1=" << x1.real()<<"+"<<x1.imag()<<"i;"
<<"x2=" << x2.real()<<"+"<<x2.imag()<<"i";
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a3188709ccd84efdadc3ee28dde3a4aa",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "d62b329f91df4c458d54274ab3ac34ee",
"keywords": "算法初阶,排序和顺序统计量,中位数和顺序统计量,最坏情况为线性时间的选择算法"
}
\ No newline at end of file
# 海港(port)
海港(port)
【问题描述】
小谢是海港的海关工作人员,每天都有许多船只到达海港,船上通常有很多来自不同国家的乘客。
小谢对这些到达海港的船只非常感兴趣,他按照时间记录下了到达海港的每一艘船只情况;对于第i艘到达的船,他记录了这艘船只到达的时间ti(单位:秒),船上的乘客数量Ki,以及每名乘客的国籍x(i,1),x(i,2),···,x(i,k)。
小谢统计了n艘船的信息,希望你帮忙计算出以每一艘船到达时间为止的24小时(24小时=86400秒)内所有乘船到达的乘客来自多少个不同的国家。
形式化的讲,你需要计算n条信息。对于输出的第i条信息,你需要统计满足:ti-86400<tp<=ti的船只p,在所有的x(p,j)中,总共有多少个不同的数。
输入格式:第1行输入一个正整数n,表示小谢统计了n艘船的信息。
接下来的n行,每行描述一艘船的信息:前两个整数ti和ki分别表示这艘船到达海港的时间和船上的乘客数量,接下来的ki个整数x(i,j)表示从小谢第一次上班开始计时,这艘船在第ti秒到达海港。
保证1<=n<=105,ki>=1,∑ki<=3×105,1<=x(i,j)<=105,1<=ti-1<ti<=109。其中∑ki表示所有ki的和。输出格式
输出n行,第i行输出一个整数表示第i艘船到达后的统计信息。
【输入样例1】
3
1 4 4 1 2 2
2 2 2 3
10 1 3
【输出样例1】
3
4
4
样例1说明:第一艘船在第一秒到达海港,最近24小时到达的船是第一艘船,共4个乘客,分别来自国家4,1,2,2,共来自3个不同的国家。
第2艘船在第2秒到达海港,最近24小时到达的船是第1艘船和第2艘船,共有4+2=6个乘客,分别来自国家4,1,2,2,2,3,共来自4个不同的国家;
第三艘船在第10秒到达海港,最近24小时到达的船是第1艘船、第2艘船和第3艘船,共有4+2+1=7个乘客,分别是来自国家4,1,2,2,2,3,3,共来自4个不同的国家。
【输入样例2】
4
1 4 1 2 2 3
3 2 2 3
86401 2 3 4
86402 1 5
【输出样例2】
3
3
3
4
样例2说明:第一艘船在第一秒到达海港,最近24小时到达的船是第1艘,共有4个乘客,分别是来自国家1,2,2,3,共来自3个不同的国家。
第2艘船是第3秒到达海港,最近24小时到达的船是第一艘船和第2艘船,共有4+2=6个乘客,分别来自1,2,2,3,2,3,共来自3个不同的国家
第3艘船是第86401秒到达海港,最近24小时到达的船是第2艘船和第3艘船,共有2+2=4个乘客,分别来自2.3,3,4,共来自3个不同的国家
第4艘船是第86402秒到达海港,最近24小时到达的船是第2艘船、第3艘船和第4艘船,共有2+2+1=5个乘客,分别来自2,3,3,4,5,共来自4个不同的国家
## template
```cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int a[100100];
int people[500100];
struct node{
int country;
int time;
};
queue<node>q;
int main(){
int n,sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int t,p;
scanf("%d%d",&t,&p);
node temp;
temp.time=t;
for(int i=1;i<=p;i++){
int cty;
scanf("%d",&cty);
temp.country=cty;
q.push(temp);
if(!people[cty]) sum++;
people[cty]++;
}
while(1){
node old;
old=q.front();
if(temp.time-86400>=old.time)
{
int tc=old.country;
people[tc]--;
if(!people[tc]) sum--;
q.pop();
}
else break;
}
cout<<sum<<endl;
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-27b3572f34b748abb392e1a6d5af1b83",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "ab1b6d86f0904f9a8b540e4219f28445",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 计算出现次数最多的整数及其出现次数
<p>【问题描述】
输入一组无序的整数&#xff0c;编程输出其中出现次数最多的整数及其出现次数。
【输入形式】
先从标准输入读入整数的个数&#xff08;大于等于1&#xff0c;小于等于100&#xff09;&#xff0c;然后在下一行输入这些整数&#xff0c;各整数之间以一个空格分隔。
【输出形式】
在标准输出上输出出现次数最多的整数及其出现次数&#xff0c;两者以一个空格分隔&#xff1b;若出现次数最多的整数有多个&#xff0c;则按照整数升序分行输出。
【样例输入】
10
0 -50 0 632 5813 -50 9 -50 0 632
【样例输出】
-50 3
0 3
【样例说明】
输入了10个整数&#xff0c;其中出现次数最多的是-50和0&#xff0c;都是出现3次。</p>
## template
```cpp
#include <stdio.h>
int main()
{
int a[50],b[50],c[50],n,i,j,t,max;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
j=0;
t=-1;
for(i=0;i<n-1;i++)
{
if(a[i]!=a[i+1])
{
b[j]=i-t;
c[j]=i;
t=i;
j++;
}
}
b[j]=n-1-t;
c[j]=n-1;
max=b[0];
for(i=1;i<=j;i++)
{
if(max<b[i])
{
max=b[i];
}
}
for(i=0;i<=j;i++)
if(b[i]==max)
{
t=c[i];
printf("%d %d\n",a[t],b[i]);
}
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-8c3e3334da8145e0b1f40a1ae6edb9a3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "bf7cc25b26a2469bbed95edac651f686",
"keywords": "图算法,算法高阶,图的表示,基本的图算法"
}
\ No newline at end of file
# 六角填数
<p>![图片说明](https://img-ask.csdn.net/upload/202006/14/1592104139_240178.png)
六角填数
题目描述
如下图所示六角形中,有12个点,依次填入1~12的数字,使得每条直线上的数字之和都相同。其中,已经替你填好了点1,2,3的数字,请你计算其他位置所代表的数字是多少?
输入
输入仅一行,以空格隔开,分别表示已经填好的点1,2,3的数字。
输出
输出仅一行,以空格隔开,分别表示所有位置所代表的数字。
样例输入:
1 8 2
样例输出:
1 8 2 9 7 11 10 12 3 5 6 4</p>
## template
```cpp
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define eps 10e-10
#define N 15
int a[N];
bool vis[N];
void dfs(int x){
if(x == 1 || x == 2 || x == 3){
dfs(x+1);
return ;
}
if(x > 12){
int t[6];
t[0] = a[1] + a[3] + a[6] + a[8];
t[1] = a[1] + a[4] + a[7] + a[11];
t[2] = a[2] + a[3] + a[4] + a[5];
t[3] = a[2] + a[6] + a[9] + a[12];
t[4] = a[8] + a[9] + a[10] + a[11];
t[5] = a[12] + a[10] + a[7] + a[5];
for(int i = 1; i < 6; ++i){
if(t[i] != t[i-1])return ;
}
for (int i = 1; i <= 12; i++) cout << a[i] << " ";
return ;
}
for(int i = 1;i < 13; ++i){
if(!vis[i]){
vis[i] = 1;
a[x] = i;
dfs(x+1);
vis[i] = 0;
}
}
}
int main(){
memset(vis,0,sizeof(vis));
cin >> a[1];
vis[a[1]] = 1;
cin >> a[2];
vis[a[2]] = 1;
cin >> a[3];
vis[a[3]] = 1;
dfs(1);
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-2c8a0ab8ef3d4af78edfc94cbb48f3a3",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "56407e02af7445bf94d238b1291de26e",
"keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解"
}
\ No newline at end of file
# 阶乘和数
一个正整数如果等于组成它的各位数字的阶乘之和,该整数称为阶乘和数。
例如,145=1!+4!+5!,则145是一个三位阶乘和数。
请输出所有阶乘数(不会超过十万)
## template
```cpp
#include <stdio.h>
int b[10] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
int main(){
    int x, sum = 0, a;
    for(int j = 1; j <= 100000; j++){
        sum = 0; 
        a = j;
        while(j != 0){
            x = j % 10;
            j /= 10;
            sum += b[x];
        }
        j = a;
        if(sum == a){
            printf("%d ", j);
        }
    }
    return 0;
} 
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-a799f09791bc4c42b53fd5791599f80a",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "4c663898592546f7854c3a7bbc7443ef",
"keywords": "桶排序,算法初阶,线性时间排序,排序和顺序统计量"
}
\ No newline at end of file
# 写一个函数,对任意一维数组进行降序排序
<p>在主函数中随机生成一有n个元素的一维数组(元素的取值范围载10-90之间),调用排序函数对该数组进行排序,并输出排序结果。</p>
## template
```cpp
#include <stdio.h>
#include <random>
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
void InsertSort(int a[], int n)
{
for (int i = 1; i<n; i++) {
if (a[i] < a[i - 1]) {
int j = i - 1;
int x = a[i];
a[i] = a[i - 1];
while (x < a[j]) {
a[j + 1] = a[j];
j--;
}
a[j + 1] = x;
}
}
}
int main()
{
cout << "请输入产生多个随机数:";
int ranNum[100],num = 0;
srand((unsigned)time(NULL));
cin >> num;
cout << "随机数组:";
for (int i = 0; i < num; i++)
{
ranNum[i] = 10 + (rand() % 80);
cout << " " << ranNum[i];
}
cout << endl;
InsertSort(ranNum, num);
cout << "排序后整数序列:";
for (int j = num-1; j >= 0; j--) {
cout << ranNum[j] << " ";
}
cout << endl;
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4ce43b7cb7f94673840071d3fc494104",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "3692981daccb4996bb72f68585ec1015",
"keywords": "算法高阶,字符串匹配,算法问题选编,利用有限自动机进行字符串匹配"
}
\ No newline at end of file
# 结合两个字符串
写一个结合两个字符串的方法,从第一个字符串中取出一个字符,然后从第二个字符串中取出一个字符,以此类推。一旦一个字符串没有字符,它就应该继续使用另一个字符串
输入:两个字符串,如s1="day"和s2="time"
输出:一个结果字符串,对于上面的输入情况,它将是“dtaiyme”。
## template
```cpp
#include <iostream>
#include <string>
using namespace std;
string StrCon(const string& a, const string& b)
{
string c;
int n = a.size(), m = b.size();
if (0 == n) return a;
if (0 == m) return b;
int i, j;
for (i = 0, j = 0; i < n && j < m; ++i, ++j)
{
c += a[i];
c += b[i];
}
while (i < n)
c += a[i++];
while (j < m)
c += b[j++];
return c;
}
int main()
{
string s = "day", t = "time";
cout << StrCon(s, t) << endl;
system("pause");
return 0;
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-00a63626bbf341f69ef4f53100e4e26b",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "aa3bbb913e4c48e982dea173d55f701a",
"keywords": "算法初阶,基础知识,特征序列,概率分析和随机算法,概率分析和指示器随机变量的进一步使用"
}
\ No newline at end of file
# 数组排序
<p>给定n&#xff08;n是偶数&#xff0c;且n≤100&#xff09;个正整数&#xff0c;所有正整数均≤10000&#xff1b;从前往后依次遍历这个数组&#xff0c;每两个为一组进行处理&#xff0c;若一组中的任意一个元素能被3或者5整除&#xff0c;则交换这两个元素的位置&#xff1b;否则不动&#xff1b;全部处理完成后&#xff0c;逆序输出整个数组。
例如给定序列&#xff1a; 99 35 83 38 &#xff0c; 处理完成后得到&#xff1a;38 83 99 35
给定序列&#xff1a; 6 7 3 4 &#xff0c;处理完成后得到&#xff1a;3 4 6 7</p>
## template
```cpp
#include <stdio.h>
#include <math.h>
int main()
{
int i,j,n,a[10005],t;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
if(i%2==1){
if((a[i]%3==0)||(a[i]%5==0)||(a[i-1]%3==0)||(a[i-1]%5==0)){
t=a[i];
a[i]=a[i-1];
a[i-1]=t;
}
}
}
for(i=n-1;i>=0;i--){
printf("%d ",a[i]);
}
}
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```
\ No newline at end of file
{
"node_id": "dailycode-4472f0cc2ab5465580dc1a55d94a49d2",
"keywords": [],
"children": [],
"export": [
"solution.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "csdn.net",
"source": "solution.md",
"exercise_id": "b70f9ae78a9e4776b7d714fcc00541ad",
"keywords": "图算法,算法高阶,图的表示,基本的图算法"
}
\ No newline at end of file
# 迷宫问题,需要用递归
<p>问题描述&#xff1a;一只老鼠在一个n×n迷宫的入口处&#xff0c;它想要吃迷宫出口处放着奶酪&#xff0c;问这只老鼠能否吃到奶酪&#xff1f;如果可以吃到&#xff0c;请给出一条从入口到奶酪的路径。
思考&#xff1a;解决问题之前&#xff0c;我们首先要做的就是仔细研究问题&#xff0c;找出问题的已知条件和要得到的是什么。和解数学问题、物理问题一样要先弄懂问题。那么&#xff0c;老鼠走迷宫问题的已知条件有什么呢&#xff1f;
数学模型重新定义问题&#xff1a;
问题&#xff1a;问老鼠能否吃到奶酪就是问能否找到一条从迷宫入口到出口的路径。如果不能找到&#xff0c;那么老鼠就吃不到奶酪&#xff1b;如果能够找到&#xff0c;那么就给出这条路径。
观察10×10的迷宫。这个迷宫其实是由10×10&#61;100个格子组成的&#xff0c;其中绿色格子代表墙&#xff0c;白色格子代表路&#xff0c;如图&#xff08;1&#xff09;所示。“绿色格子代表墙&#xff0c;白色格子代表路”是用语言形式描述的&#xff0c;需要转换成数学的形式。用1和0分别定义绿色格子和白色格子&#xff0c;可以得到如图&#xff08;2&#xff09;的迷宫。
将上面10×10的迷宫定义为如下的二维数组&#xff0c;
m[10][10]&#61;[1,1,1,0,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,1,1,
1,0,1,1,1,1,1,0,0,1,
1,0,1,0,0,0,0,1,0,1,
1,0,1,0,1,1,0,0,0,1,
1,0,0,1,1,0,1,0,1,1,
1,1,1,1,0,0,0,0,1,1,
1,0,0,0,0,1,1,1,0,0,
1,0,1,1,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1]
有了对迷宫的数学定义&#xff0c;就可以很简单的定义迷宫的入口和出口了。迷宫的入口是m[0][3]&#xff0c;出口是m[7][9]。老鼠走迷宫问题就是要找一条从入口到出口的路径&#xff0c;如果存在就返回这条路径&#xff1b;如果不存在&#xff0c;就返回不存在这种路径。也就是说&#xff0c;要在二维数组m中找一条从m[0][3]到m[7][9]全部为0的路径。
请使用递归解决迷宫路径查找问题。
</p>
## template
```python
def maze(m, n, route, pos, export):
"""走迷宫
m - 迷宫数组,列表
n - 迷宫阶数
route - 可能的路线,列表
pos - 当前位置,元组
export - 出口位置,元组
"""
route.append(pos)
if pos == export:
print(route)
if pos[0] > 0 and m[pos[0]-1][pos[1]] == 0 and (pos[0]-1,pos[1]) not in route:
maze(m, n, route[:], (pos[0]-1,pos[1]), export)
if pos[0] < n-1 and m[pos[0]+1][pos[1]] == 0 and (pos[0]+1,pos[1]) not in route:
maze(m, n, route[:], (pos[0]+1,pos[1]), export)
if pos[1] > 0 and m[pos[0]][pos[1]-1] == 0 and (pos[0],pos[1]-1) not in route:
maze(m, n, route[:], (pos[0],pos[1]-1), export)
if pos[1] < n-1 and m[pos[0]][pos[1]+1] == 0 and (pos[0],pos[1]+1) not in route:
maze(m, n, route[:], (pos[0],pos[1]+1), export)
m = [
[1,1,1,0,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,1,1],
[1,0,1,1,1,1,1,0,0,1],
[1,0,1,0,0,0,0,1,0,1],
[1,0,1,0,1,1,0,0,0,1],
[1,0,0,1,1,0,1,0,1,1],
[1,1,1,1,0,0,0,0,1,1],
[1,0,0,0,0,1,1,1,0,0],
[1,0,1,1,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1]
]
maze(m, len(m), list(), (0,3), (7,9))
```
## 答案
```python
```
## 选项
### A
```python
```
### B
```python
```
### C
```python
```
\ No newline at end of file
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
import sys import sys
import uuid import uuid
import json import json
import shutil
def get_files_path(file_dir, filetype='.txt'): def get_files_path(file_dir, filetype='.txt'):
...@@ -48,12 +49,15 @@ def classify_exercises(): ...@@ -48,12 +49,15 @@ def classify_exercises():
'java': '.java', 'java': '.java',
'python': '.py' 'python': '.py'
} }
answer_dirs = ['data_backup/cpp_code_json', 'data_backup/java_code_json', 'data_backup/python_code_json'] answer_dirs = ['data_backup/cpp_code_json', 'data_backup/java_code_json', 'data_backup/python_code_json']
for dir in answer_dirs: for dir in answer_dirs:
count_simple = 0
count_middle = 0
count_diff = 0
language = dir.split('/')[-1].split('_')[0] language = dir.split('/')[-1].split('_')[0]
ext = language_ext[language] ext = language_ext[language]
files = get_files_path(dir, '.json') files = get_files_path(dir, '.json')
count = 0
for file_path in files: for file_path in files:
data = load_json(file_path) data = load_json(file_path)
status = data['status'] status = data['status']
...@@ -77,6 +81,7 @@ def classify_exercises(): ...@@ -77,6 +81,7 @@ def classify_exercises():
solution_json_data['author'] = 'csdn.net' solution_json_data['author'] = 'csdn.net'
solution_json_data['source'] = 'solution.md' solution_json_data['source'] = 'solution.md'
solution_json_data['exercise_id'] = uuid.uuid4().hex solution_json_data['exercise_id'] = uuid.uuid4().hex
solution_json_data['keywords'] = keywords
solution_md_data = f"# {question_title}\n\n{question_content}\n\n## template\n\n```{language}\n{answer}\n```\n\n## 答案\n\n```{language}\n\n```\n\n## 选项\n\n### A\n\n```{language}\n\n```\n\n### B\n\n```{language}\n\n```\n\n### C\n\n```{language}\n\n```" solution_md_data = f"# {question_title}\n\n{question_content}\n\n## template\n\n```{language}\n{answer}\n```\n\n## 答案\n\n```{language}\n\n```\n\n## 选项\n\n### A\n\n```{language}\n\n```\n\n### B\n\n```{language}\n\n```\n\n### C\n\n```{language}\n\n```"
# print(solution_md_data) # print(solution_md_data)
...@@ -103,27 +108,24 @@ def classify_exercises(): ...@@ -103,27 +108,24 @@ def classify_exercises():
language_dir = '' language_dir = ''
sys.exit("语言类型异常") sys.exit("语言类型异常")
dst_dir = os.path.join(root_dir, language_dir) dst_dir = os.path.join(root_dir, language_dir)
dir_list_ = os.listdir(dst_dir) if difficulty == '简单':
dir_list = [] count_simple +=1
for i in dir_list_: exercises_dir = os.path.join(dst_dir, str(count_simple) + '.exercises')
if os.path.isdir(i): elif difficulty == '中等':
dir_list.append(i) count_middle +=1
number = len(dir_list) + 1 exercises_dir = os.path.join(dst_dir, str(count_middle) + '.exercises')
dst_dir = os.path.join(dst_dir, str(number) + '.exercises') elif difficulty == '困难':
count_diff +=1
solution_json_path = os.path.join(dst_dir, 'solution.json') exercises_dir = os.path.join(dst_dir, str(count_diff) + '.exercises')
solution_md_path = os.path.join(dst_dir, 'solution.md') print(exercises_dir)
config_path = os.path.join(dst_dir, 'config.json')
solution_json_path = os.path.join(exercises_dir, 'solution.json')
solution_md_path = os.path.join(exercises_dir, 'solution.md')
config_path = os.path.join(exercises_dir, 'config.json')
print(count) if not os.path.exists(exercises_dir):
print(dst_dir) os.makedirs(exercises_dir)
print(solution_json_path)
print(solution_md_path)
print(config_path)
if not os.path.exists(dst_dir):
os.mkdir(dst_dir)
dump_json(solution_json_path, solution_json_data) dump_json(solution_json_path, solution_json_data)
dump_json(config_path, config_data) dump_json(config_path, config_data)
with open(solution_md_path, 'w', encoding='utf-8') as f: with open(solution_md_path, 'w', encoding='utf-8') as f:
...@@ -208,6 +210,25 @@ def classify_leetcode(): ...@@ -208,6 +210,25 @@ def classify_leetcode():
with open(solution_md_path, 'w', encoding='utf-8') as f: with open(solution_md_path, 'w', encoding='utf-8') as f:
f.write(solution_md_data) f.write(solution_md_data)
def rename_dir():
dirs = ['data/1.dailycode初阶', 'data/2.dailycode中阶', 'data/3.dailycode高阶']
for dir in dirs:
lanuages_dirs = ['1.cpp', '2.java', '3.python']
for lanuages_dir in lanuages_dirs:
lanuages_dir = os.path.join(dir, lanuages_dir)
# print(lanuages_dir)
exercises_dirs = os.listdir(lanuages_dir)
print(exercises_dirs)
for idx, exer in enumerate(exercises_dirs):
exercises_dir = os.path.join(lanuages_dir, exer)
new_exercises_dir = os.path.join(lanuages_dir, '{}.exercises'.format(idx + 1))
# print(exercises_dir)
# print(new_exercises_dir)
# os.rename(exercises_dir, new_exercises_dir)
classify_exercises() classify_exercises()
# classify_leetcode() # classify_leetcode()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册