1323. Maximum 69 Number*

1323. Maximum 69 Number*

https://leetcode.com/problems/maximum-69-number/

题目描述

Given a positive integer num consisting only of digits 6 and 9.

Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).

Example 1:

Input: num = 9669
Output: 9969
Explanation: 
Changing the first digit results in 6669.
Changing the second digit results in 9969.
Changing the third digit results in 9699.
Changing the fourth digit results in 9666. 
The maximum number is 9969.

Example 2:

Input: num = 9996
Output: 9999
Explanation: Changing the last digit 6 to 9 results in the maximum number.

Example 3:

Input: num = 9999
Output: 9999
Explanation: It is better not to apply any change.

Constraints:

  • 1 <= num <= 10^4
  • num's digits are 6 or 9.

C++ 实现 1

class Solution {
public:
    int maximum69Number (int num) {
        auto s = std::to_string(num);
        for (auto &c : s) {
            if (c != '9') {
                c = '9'; 
                break;
            }
        } 
        return std::stoi(s);
    }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I can answer your questions about Python and data analysis. Here are the steps to complete the tasks you requested: 1. To import the "学生成绩.xls" Excel file, we can use the pandas library in Python: ```python import pandas as pd df = pd.read_excel('学生成绩.xls') ``` This will import the Excel file as a pandas dataframe called "df". 2. To sort the dataframe by student ID, we can use the sort_values() function: ```python df_sorted = df.sort_values('学号') ``` This will sort the dataframe by the "学号" column. 3. To get the descriptive statistics of the grades, we can use the describe() function: ```python stats = df['总分'].describe() print(stats) ``` This will print the maximum, minimum, mean, and standard deviation of the "总分" column. 4. To plot a scatter plot of "总分" versus student ID, we can use the matplotlib library: ```python import matplotlib.pyplot as plt plt.scatter(df_sorted['学号'], df_sorted['总分']) plt.xlabel('学号') plt.ylabel('总分') plt.show() ``` This will plot a scatter plot of "总分" versus student ID. 5. To plot a pie chart of the number of students in each grade range, we can use the pandas cut() function: ```python bins = [60, 69, 79, 89, 100] labels = ['60-69', '70-79', '80-89', '90-100'] df_sorted['分数段'] = pd.cut(df_sorted['总分'], bins=bins, labels=labels) counts = df_sorted['分数段'].value_counts() plt.pie(counts, labels=labels, autopct='%1.1f%%') plt.show() ``` This will plot a pie chart of the number of students in each grade range. 6. To plot a histogram of each subject's grades, we can use the matplotlib hist() function: ```python plt.hist(df_sorted['语文'], alpha=0.5, label='语文') plt.hist(df_sorted['数学'], alpha=0.5, label='数学') plt.hist(df_sorted['英语'], alpha=0.5, label='英语') plt.legend() plt.show() ``` This will plot a histogram of each subject's grades.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值