bestcoder round #12

1001 So easy

Problem Description
Small W gets two files. There are n integers in each file. Small W wants to know whether these two files are same. So he invites you to write a program to check whether these two files are same. Small W thinks that two files are same when they have the same integer set.
For example file A contains (5,3,7,7),and file B contains (7,5,3,3). They have the same integer set (3,5,7), so they are same.
Another sample file C contains(2,5,2,5), and file D contains (2,5,2,3).

The integer set of C is (2,5),but the integer set of D is (2,3,5),so they are not same.
Now you are expected to write a program to compare two files with size of n.

Input
Multi test cases (about 100). Each case contain three lines. The first line contains one integer n represents the size of file. The second line contains n integers a1,a2,a3,…,an - represents the content of the first file. The third line contains n integers b1,b2,b3,…,bn - represents the content of the second file.
Process to the end of file.
1≤n≤100
1≤ai,bi≤1000000000

Output
For each case, output “YES” (without quote) if these two files are same, otherwise output “NO” (without quote).

Sample Input
3
1 1 2
1 2 2
4
5 3 7 7
7 5 3 3
4
2 5 2 3
2 5 2 5
3
1 2 3
1 2 4

Sample Output
YES
YES
NO
NO

题解

简单的SET运用,不难,写的时候脑抽写搓了……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int ()
{
set<int>s1,s2;
int n;
while(~scanf("%d",&n))
{
s1.clear();
s2.clear();
int tt;
for(int i = 0; i < n; i++)
{
scanf("%d",&tt);
s1.insert(tt);
}
for(int i = 0; i < n; i++)
{
scanf("%d",&tt);
s2.insert(tt);
}
if(s1.size() != s2.size())
{
printf("NOn");
continue;
}
int flag = 0;
set<int>::iterator it1, it2;
for(it1 = s1.begin(),it2 = s2.begin(); it1!=s1.end()&&it2!=s2.end(); it1++,it2++)
{
if(*it1 != *it2)
{
flag = 1;
break;
}
}
if(flag)
{
printf("NOn");
}
else
printf("YESn");
}
return 0;
}

1002 Help him

Problem Description
As you know, when you want to hack someone’s program, you must submit your test data. However sometimes you will submit invalid data, so we need a data checker to check your data. Now small W has prepared a problem for BC, but he is too busy to write the data checker. Please help him to write a data check which judges whether the input is an integer ranged from a to b (inclusive).
Note: a string represents a valid integer when it follows below rules.

  1. When it represents a non-negative integer, it contains only digits without leading zeros.
  2. When it represents a negative integer, it contains exact one negative sign (‘-‘) followed by digits without leading zeros and there are no characters before ‘-‘.
  3. Otherwise it is not a valid integer.

Input
Multi test cases (about 100), every case occupies two lines, the first line contain a string which represents the input string, then second line contains a and b separated by space. Process to the end of file.

Length of string is no more than 100.
The string may contain any characters other than ‘n’,’r’.
-1000000000≤a≤b≤1000000000

Output
For each case output “YES” (without quote) when the string is an integer ranged from a to b, otherwise output “NO” (without quote).

Sample Input
10
-100 100
1a0
-100 100

Sample Output
YES
NO

题解

判断输入的数是否合法,确实如一开始想的那样是一道字符转int,int转字符的题,但是trick其实蛮多的,输入的时候要用getline,要处理末尾空格,要判断0与一堆零的区别,要判断前导零;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstdio>
#include <algorithm>
#include <sstream>
#include<iostream>
using namespace std;
int ()
{

int t,a,b;
string s,s1;
while(getline(cin,s))

{
stringstream str,str1;
cin>>a>>b;
getchar();
str<<s;
str>>t;
str1<<t;
str1>>s1;
if(s[0]=='0')
{
if(s=="0"&&s.size()==1)
{
if(a<=0&&b>=0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else cout<<"NO"<<endl;

continue;
}
if(s==s1&&t>=a&&t<=b)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;

//
}
return 0;
}