【编程题目 |100分】最长子字符串的长度2022 Q2考试题 2024 Q1考试题 C


时间限制:C/C++ 1秒,其他语言 2秒

空间限制:C/C++262144K,其他语言524288K

64bit IO Format:%lld


本题可使用本地IDE编码,不能使用本地已有代码,无跳出限制,

编码后请点击”保存并调试“按钮进行代码提交。


题目描述

【最长子字符串的长度】

给你一个字符串 s,字符串s首尾相连成一个环形 ,请你在环中找出 ‘o’ 字符出现了偶数次最长子字符串的长度。

输入描述

输入是一串小写字母组成的字符串

输出描述

输出是一个整数


C++解法一


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
// 待实现函数,在此函数中填入答题代码;
int maxLength(string &s)
{
int totalO = 0;
#include <bits/stdc++.h> using namespace std; class Solution { public: // 待实现函数,在此函数中填入答题代码; int maxLength(string &s) { int totalO = 0;
#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    // 待实现函数,在此函数中填入答题代码;
    int maxLength(string &s)
    {
        int totalO = 0;

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

C++解法二


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h> using namespace std;
#include <bits/stdc++.h> 

using namespace std;

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

C


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#include <stdio.h> #include <stdlib.h> #include <string.h> using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JAVA


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.huawei.uapcc.tm.decoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
package com.huawei.uapcc.tm.decoder; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in);
package com.huawei.uapcc.tm.decoder;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看


Python解法一


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from typing import List
class Solution:
from typing import List class Solution:
from typing import List


class Solution:

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

Python解法二


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from typing import List
class Solution:
from typing import List class Solution:
from typing import List


class Solution:

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JavaScript


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, });
const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看