← 返回 uber 的题目列表Compare Two Structs or Classes for Equality
类型:online_judge
Problem: Compare Two Structs or Classes for Equality
Given two objects a and b represented as JSON values, determine whether they are exactly equal.
Each value may contain the following types:
null
boolean
integer
string
array
object / dictionary
Equality is defined as follows:
Primitive values must have the same type and the same value.
Arrays must have the same length, and elements at the same index must be recursively equal.
Objects must have exactly the same set of fields. Field order does not matter. Values for each field must be recursively equal.
You do not need to handle cyclic references.
Write a program that reads two JSON values from standard input and prints whether they are equal.
Input Format
The input contains two lines:
json_value_1
json_value_2
Each line is a valid JSON value.
Output Format
Print:
true
if the two JSON values are exactly equal; otherwise print:
false
Constraints
The total number of JSON nodes is at most 10^5.
Object field names are strings.
There are no cyclic references.
Example
Input:
{"id":1,"name":"Tom","tags":["a","b"]}
{"name":"Tom","tags":["a","b"],"id":1}
Output:
true
Example
Input
{"id":1,"name":"Tom","tags":["a","b"]}
{"name":"Tom","tags":["a","b"],"id":1}
Output
true