您的答案為: 28 正確答案為: 28
這個是錯在哪裡?
程式碼:
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int size;
while(cin>>size){
int *score = new int[size];
for(int i=0;i<size;i++)cin>>score[i];
sort(score,score+size);
for(int i=0;i<size;i++)cout<<score[i]<<' ';
cout<<endl;
if(score[0]>=60)cout<<"best case"<<endl;
else{
int i=size-1;
while(score[i]>=60)i--;
cout<<score[i]<<endl;
};
if(score[size-1]<60)cout<<"worst case"<<endl;
else{
int i=0;
while(score[i]<60)i++;
cout<<score[i]<<endl;
}
delete[] score;
}
return 0;
}
您的答案為: 28 正確答案為: 28
這個是錯在哪裡?
程式碼:
#include
#include
using namespace std;
int main(){
int size;
while(cin>>size){
int *score = new int[size];
for(int i=0;i<size;i++)cin>>score[i];
sort(score,score+size);
for(int i=0;i<size;i++)cout<<score[i]<<' ';
cout<<endl;
if(score[0]>=60)cout<<"best case"<<endl;
else{
int i=size-1;
while(score[i]>=60)i--;
cout<<score[i]<<endl;
};
if(score[size-1]<60)cout<<"worst case"<<endl;
else{
int i=0;
while(score[i]<60)i++;
cout<<score[i]<<endl;
}
delete[] score;
}
return 0;
}
換行前的最後一個不能輸出空格
我也是一樣,出現上面的訊息,求解
while True:
try:
n = eval(input())
x=[]
x = input().strip()
x=x.split(' ')
for j in range(len(x)):
x[j] = int(x[j])
x.sort()
w = True
b = True
for j in x:
if j < 60:
b = False
if j >= 60:
w = False
print(j,'',end='')
print(end='\n')
t = []
if b == False:
for j in x:
if j < 60:
t.append(j)
#print(t)
print(t[len(t)-1])
else:
print('best case')
p=[]
if w == False:
for j in x:
if j >= 60:
p.append(j)
print(p[0])
else:
print('worst case')
except:
break