你题目的解答代码如下:
#include <stdio.h>
#include <iostream>
using namespace std;
#include <string.h>//strlen
bool IS(char arr[], int left, int right) {
int up[26] = { 0 };
int low[26] = { 0 };
for (int i = left; i < right; i++) {
if (arr[i] >= 'a'&&arr[i] <= 'z') {
low[arr[i] - 'a'] = 1;
}
else { up[arr[i] - 'A'] = 1; }
}
for (int i = 0; i < 26; i++) {
if (up[i]+low[i] == 1) return false; //修改
}
return true; //修改
}
int main() {
char s[100];
scanf_s("%s", s,100); //修改
int n = strlen(s);
int left = 0, right = 0, count = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (IS(s, i, j) == true && j - i > count) { //修改
left = i;
count = j - i; //修改
}
}
}
char *p;
p = (char*)malloc((count + 1)*(sizeof(char)));
int i = 0;
for (i; i < count; i++) {
p[i] = s[left];
left++;
}
p[i] = '\0';
printf("%s", p);
return 0;
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
兄弟,问问题至少先学会问问题嘛
不放题目
不放报错内容
这怎么给你看