A - 最小的二进制数&E - 法法在分配工作&F - 法法要穿过大门

A - 最小的二进制数

像题目中所述,把0都写出来,如果有1就在最前面输出一个1就好啦

String can be called correct if it consists of characters “0” and “1” and there are no redundant leading zeroes. Here are some examples: “0”, “10”, “1001”.
You are given a correct string s.
You can perform two different operations on this string:

swap any pair of adjacent characters (for example, “101” “110”);
replace “11” with “1” (for example, “110” “10”).

Let val(s) be such a number that s is its binary representation.
Correct string a is less than some other correct string b iff val(a) < val(b).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

Input

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.
The second line contains the string s consisting of characters “0” and “1”. It is guaranteed that the string s is correct.

Output

Print one string — the minimum correct string that you can obtain from the given one.

Examples

Input
4
1001
Output
100
Inpuut
1
1
Output
1

#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <complex>
#include <cassert>
#include <sstream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <list>
using namespace std;
int main(){
	int n;
	char s[110];
	cin>>n;
	cin>>s;
	int f=0,count=0;
	for(int i=0;i<n;i++){
		if(s[i]=='1')	f++;
		else		count++;
	}
	if(f)	cout<<1;
	for(int i=1;i<=count;i++){
		cout<<'0';
	}
}

E - 法法在分配工作

就简单判断n-x/x是否等于0

Fafa owns a company that works on huge projects. There are n employees in Fafa’s company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.

Input

The input consists of a single line containing a positive integer n (2 ≤ n ≤ 105) — the number of employees in Fafa’s company.

Output

Print a single integer representing the answer to the problem.

Example

Input
2
Output
1
Input
10
Output
3

Note

In the second sample Fafa has 3 ways:
choose only 1 employee as a team leader with 9 employees under his responsibility.
choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
choose 5 employees as team leaders with 1 employee under the responsibility of each of them.

#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <complex>
#include <cassert>
#include <sstream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <list>
using namespace std;
int main(){
	int n;
	char s[110];
	cin>>n;
	cin>>s;
	int f=0,count=0;
	for(int i=0;i<n;i++){
		if(s[i]=='1')	f++;
		else		count++;
	}
	if(f)	cout<<1;
	for(int i=1;i<=count;i++){
		cout<<'0';
	}
}

F - 法法要穿过大门(补题)

WA了很多次 因为图看错了而且没翻译对题意…其实只要判断每次有没有去别的国家就能做对

Two neighboring kingdoms decided to build a wall between them with
some gates to enable the citizens to go from one kingdom to another.
Each time a citizen passes through a gate, he has to pay one silver
coin. The world can be represented by the first quadrant of a plane
and the wall is built along the identity line (i.e. the line with the
equation x = y). Any point below the wall belongs to the first kingdom
while any point above the wall belongs to the second kingdom. There is
a gate at any integer point on the line (i.e. at points (0, 0),
(1, 1), (2, 2), …). The wall and the gates do not belong to any of
the kingdoms. Fafa is at the gate at position (0, 0) and he wants to
walk around in the two kingdoms. He knows the sequence S of moves he
will do. This sequence is a string where each character represents a
move. The two possible moves Fafa will do are ‘U’ (move one step up,
from (x, y) to (x, y + 1)) and ‘R’ (move one step right, from (x, y)
to (x + 1, y)). Fafa wants to know the number of silver coins he
needs to pay to walk around the two kingdoms following the sequence S.
Note that if Fafa visits a gate without moving from one kingdom to
another, he pays no silver coins. Also assume that he doesn’t pay at
the gate at point (0, 0), i. e. he is initially on the side he needs.

Input

The first line of the input contains single integer n (1 ≤ n ≤ 105) —
the number of moves in the walking sequence. The second line contains
a string S of length n consisting of the characters ‘U’ and ‘R’
describing the required moves. Fafa will follow the sequence S in
order from left to right.

Output

On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

Examples

Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2

Note

Thefigure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.

#include <stdio.h>
int main(){
	long long n,u=0,r=0,ans=0;
	char s[100010];
	scanf("%ld",&n);
	scanf("%s",s);
	for(int i=0;i<n-1;i++){
		if(s[i]=='U')	u++;
		else		r++;
		if(u==r&&s[i+1]==s[i])	ans++;
	}
	printf("%ld",ans);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值