A - New Year
题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
Constraints
- 1≤M≤23
- Mis an integer.
Input
Input is given from Standard Input in the following format:
M
Output
If we have x hours until New Year at M o'clock on 30th, December, print x.
Sample Input 1
Copy
21
Sample Output 1
Copy
27
We have 27 hours until New Year at 21 o'clock on 30th, December.
Sample Input 2
Copy
12
Sample Output 2
Copy
36
1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 int n;
6 while(cin>>n){
7 cout<<24-n+24<<endl;
8 }
9 return 0;
10 }
View Code
B - Postal Code
题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_b
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -
, and the other characters are digits from 0
through 9
.
You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
Constraints
- 1≤A,B≤5
- |S|=A+B+1
- Sconsists of
-
and digits from0
through9
.
Input
Input is given from Standard Input in the following format:
A B
S
Output
Print Yes
if S follows the postal code format in AtCoder Kingdom; print No
otherwise.
Sample Input 1
Copy
3 4
269-6650
Sample Output 1
Copy
Yes
The (A+1)-th character of S is -
, and the other characters are digits from 0
through 9
, so it follows the format.
Sample Input 2
Copy
1 1
---
Sample Output 2
Copy
No
S contains unnecessary -
s other than the (A+1)-th character, so it does not follow the format.
Sample Input 3
Copy
1 2
7444
Sample Output 3
Copy
No
1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 int a,b;
6 while(cin>>a>>b){
7 string s;
8 cin>>s;
9 int l=s.length();
10 int flag=1;
11 for(int i=0;i<l;i++){
12 if(i==a&&s[i]!='-'){
13 flag=0;
14 break;
15 }
16 if(i!=a&&!(s[i]<='9'&&s[i]>='0')){
17 flag=0;
18 break;
19 }
20 }
21 if(flag) cout<<"Yes"<<endl;
22 else cout<<"No"<<endl;
23 }
24 return 0;
25 }
View Code