一开始:
#include<bits/stdc++.h>
using namespace std;
int n,t;
int a[1005],bb=1,cc=1;
double b[1005],c[1005],l;
int main(){
cin>>t;
for(int i=1;i<=t;i++){
cin>>n;
for(int j=1;j<=n;j++){
cin>>a[j];
}
for(int j=1;j<=n;j++){
cin>>l;
if(a[j]==0){
b[bb]=l;
bb++;
}
if(a[j]==1){
c[cc]=l;
cc++;
}
}
sort(b+1,b+bb);
sort(c+1,c+cc);
for(int j=1;j<=bb-1;j++){
cout<<b[j]<<" ";
}
cout<<endl;
for(int j=1;j<=cc-1;j++){
cout<<c[j]<<" ";
}
}
return 0;
}
只有九十分,最后wa 然后:
#include<bits/stdc++.h>
using namespace std;
int t;
int a[1005];
double b[1005],c[1005];
int main(){
cin>>t;
for(int i=1;i<=t;i++){
int n;
cin>>n;
for(int j=1;j<=n;j++){
cin>>a[j];
}
int bb=1,cc=1;
double l;
for(int j=1;j<=n;j++){
cin>>l;
if(a[j]==0){
b[bb]=l;
bb++;
}
if(a[j]==1){
c[cc]=l;
cc++;
}
}
sort(b+1,b+bb);
sort(c+1,c+cc);
for(int j=1;j<=bb-1;j++){
cout<<b[j]<<" ";
}
cout<<endl;
for(int j=1;j<=cc-1;j++){
cout<<c[j]<<" ";
}
}
return 0;
}
只是把变量定义在int main里面就re 最后:
#include<bits/stdc++.h>
using namespace std;
long long t;
long long a[1000005];
double b[1000005],c[1000005];
int main(){
cin>>t;
for(int i=1;i<=t;i++){
long long n;
cin>>n;
for(int j=1;j<=n;j++){
cin>>a[j];
}
long long bb=1,cc=1;
double l;
for(int j=1;j<=n;j++){
cin>>l;
if(a[j]==0){
b[bb]=l;
bb++;
}
if(a[j]==1){
c[cc]=l;
cc++;
}
}
sort(b+1,b+bb);
sort(c+1,c+cc);
for(int j=1;j<=bb-1;j++){
cout<<b[j]<<" ";
}
cout<<endl;
for(int j=1;j<=cc-1;j++){
cout<<c[j]<<" ";
}
}
return 0;
}
数组开大了些就ac了,为何? 求神犇帮助