A - September 9
Time Limit: 2 sec / Memory Limit: 256 MB
Score : 100 points
Problem Statement
It is September 9 in Japan now.
You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
Constraints
- 10≤N≤99
Input
Input is given from Standard Input in the following format:
N
Output
If 9 is contained in the decimal notation of N, print Yes
; if not, print No
.
Sample Input 1 Copy
29
Sample Output 1 Copy
Yes
The one's digit of 29 is 9.
Sample Input 2 Copy
72
Sample Output 2 Copy
No
72 does not contain 9.
Sample Input 3 Copy
91
Sample Output 3 Copy
Yes
判断有没有9
C++:#include<bits/stdc++.h>
using namespace std;
int main(){
char cha,chb;
cin>>cha>>chb;
if(cha=='9') cout<<"Yes"<<endl;
else if(chb=='9') cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
Python:
print("Yes" if '9' in input() else "No")
B - Theater
Time Limit: 2 sec / Memory Limit: 256 MB
Score : 200 points
Problem Statement
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat li to Seat ri (inclusive).
How many people are sitting at the theater now?
Constraints
- 1≤N≤1000
- 1≤li≤ri≤100000
- No seat is occupied by more than one person.
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N l1 r1 : lN rN
Output
Print the number of people sitting at the theater.
Sample Input 1 Copy
1 24 30
Sample Output 1 Copy
7
There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.
Sample Input 2 Copy
2 6 8 3 3
Sample Output 2 Copy
4
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a,b;
int sum=0;
while(n--){
cin>>a>>b;
sum+=b-a+1;
}
cout<<sum<<endl;
}
Python:
n=int(input())
ans=0
for i in range(n):
a,b=map(int,input().split())
ans+=b-a+1
print(ans)
Time Limit: 2 sec / Memory Limit: 256 MB
Score : 300 points
Problem Statement
You are playing the following game with Joisino.
- Initially, you have a blank sheet of paper.
- Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
- Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A1,...,AN in the order she announces them. How many numbers will be written on the sheet at the end of the game?
Constraints
- 1≤N≤100000
- 1≤Ai≤1000000000(=109)
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N A1 : AN
Output
Print how many numbers will be written on the sheet at the end of the game.
Sample Input 1 Copy
3 6 2 6
Sample Output 1 Copy
1
The game proceeds as follows:
-
6 is not written on the sheet, so write 6.
-
2 is not written on the sheet, so write 2.
-
6 is written on the sheet, so erase 6.
Thus, the sheet contains only 2 in the end. The answer is 1.
Sample Input 2 Copy
4 2 5 5 2
Sample Output 2 Copy
0
It is possible that no number is written on the sheet in the end.
Sample Input 3 Copy
6 12 22 16 22 18 12
Sample Output 3 Copy
2
#include<iostream>
#include<set>
using namespace std;
set<int> st;
set<int>::iterator it;
int main(){
int n;
cin>>n;
while(n--){
int a;
cin>>a;
it=st.find(a);
if(it!=st.end()) st.erase(a);
else st.insert(a);
}
int ans=0;
for(int i=0;i<st.size();i++) ans++;
cout<<ans<<endl;
}
Python:
n=int(input())
se=set()
for i in range(n):
a=int(input())
if a in se:
se.remove(a)
else:
se.add(a)
print(len(se))