#37899: 為甚麼記憶體區段錯誤,我照著別人的寫的


0402tim@gmail.com (江威廷)

學校 : 不指定學校
編號 : 134148
來源 : [39.10.65.253]
最後登入時間 :
2024-03-26 11:40:20
d750. 11321 - Sort! Sort!! and Sort!!! -- UVa11321 | From: [39.9.101.136] | 發表日期 : 2023-10-17 14:50

#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int n,m;
bool sor(int a,int b){
if(abs(a%m)!=abs(b%m)){
return a%m<b%m;
}if(a%2==1&&b%2==1){
return a>b;
}if(a%2==0&&b%2==0){
return a<b;
}if(a%2!=b%2){
return a%2==1;
}
}
 
int main(){
 
for(int i=0;i<20;i++){
 
cin>>n>>m;
if(n==0&&m==0){
cout<<"0 0";
return 0;
}
vector<int> a(n);
for(int j=0;j<n;j++){
cin>>a[j];
}
sort(a.begin(),a.end(),sor);
cout<<n<<" "<<m<<endl;
for(int j:a){
cout<<j<<endl;
}
}
 
return 0;
}
 
#37900: Re: 為甚麼記憶體區段錯誤,我照著別人的寫的


0402tim@gmail.com (江威廷)

學校 : 不指定學校
編號 : 134148
來源 : [39.10.65.253]
最後登入時間 :
2024-03-26 11:40:20
d750. 11321 - Sort! Sort!! and Sort!!! -- UVa11321 | From: [39.9.101.136] | 發表日期 : 2023-10-17 14:51

#include
#include
#include
using namespace std;
 
int n,m;
bool sor(int a,int b){
if(abs(a%m)!=abs(b%m)){
return a%m
}if(a%2==1&&b%2==1){
return a>b;
}if(a%2==0&&b%2==0){
return a
}if(a%2!=b%2){
return a%2==1;
}
}
 
int main(){
 
for(int i=0;i<20;i++){
 
cin>>n>>m;
if(n==0&&m==0){
cout<<"0 0";
return 0;
}
vector a(n);
for(int j=0;j
cin>>a[j];
}
sort(a.begin(),a.end(),sor);
cout<
for(int j:a){
cout<
}
}
 
return 0;
}

Day1 #UVa 11321 & UVa 10041 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天 (ithome.com.tw)

#include "bits/stdc++.h"

using namespace std;

int n, m;
bool cmp(int i, int j) {
    if (i % m != j % m) {
        return i % m < j % m;
    }
    if ((i & 1) && (j & 1))
        return i > j;
    else if (!(i & 1) && !(j & 1))
        return i < j;
    else
        return i & 1;
}

int main() {
    while (cin >> n >> m, n) {
        cout << n << " " << m << endl;
        vector<int> nums(n);
        for (auto& i : nums) {
            cin >> i;
        }
        sort(nums.begin(), nums.end(), cmp);
        for (auto& i : nums)
            cout << i << endl;
    }
    cout << 0 << " " << 0 << endl;
}

 
ZeroJudge Forum