题解 | #特别的玛格丽特#

特别的玛格丽特

https://ac.nowcoder.com/acm/problem/234762

排序后与原数组比较,同一位置上的数奇偶性不变。

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		InputReader in = new InputReader();
		PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] a = new int[n], b = new int[n];
        for(int i = 0; i < n; ++i)
            a[i] = b[i] = in.nextInt();
        Arrays.sort(a);
        boolean flag = true;
        for(int i = 0; i < n; ++i) {
            if(a[i] % 2 != b[i] % 2) {
                flag = false; break;
            } 
        }
        out.println(flag ? "Yes" : "No");
 
		out.close();
	}
}
class InputReader{BufferedReader buf;StringTokenizer tok;InputReader(){buf = new BufferedReader(new InputStreamReader(System.in));}boolean hasNext(){while (tok == null || !tok.hasMoreElements()){try{tok = new StringTokenizer(buf.readLine());}catch (Exception e){return false;}}return true;}String next(){if (hasNext())
			return tok.nextToken();return null;}int nextInt(){return Integer.parseInt(next());}long nextLong(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}BigInteger nextBigInteger(){return new BigInteger(next());}BigDecimal nextBigDecimal(){return new BigDecimal(next());}}
全部评论

相关推荐

叮咚鸭:群众里面有坏人
点赞 评论 收藏
分享
oppo 应用软开 22*15+0.5*12
拿到了ssp完美:真的坎坷,但是你至少拿到这么多offer了!
点赞 评论 收藏
分享
评论
2
收藏
分享
牛客网
牛客企业服务