1. 程式人生 > >國慶練習1

國慶練習1

hide proc 開始 single ons ets word pen lower

Romaji CF 1008A

Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.

In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.

Help Vitya find out if a word ss is Berlanese.

Input

The first line of the input contains the string ss consisting of |s||s|(1|s|1001≤|s|≤100) lowercase Latin letters.

Output

Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

Input
sumimasen
Output
YES
Input
ninja
Output
YES
Input
codeforces
Output
NO

Note

In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.

In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.

題目意思:元音字符有a e i o u,輔音字符是除了元音字符以外的字母。

輔音字母後面只能跟元音字母,除了輔音字母n,它後面可以跟任意字符或者不跟字符;

元音字符後面可以跟任意字符。

給你一個字符串,如果滿足以上條件,則輸出YES,否則輸出NO。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <string>
 6 #define ll long long int
 7 char s[110];
 8 char a[6]="aeiou";
 9 int judge(char c)///判斷元音的被調函數
10 {
11     int i;
12     for(i=0;i<6;i++)
13     {
14         if(c==a[i])
15         {
16             return 1;
17             break;
18         }
19     }
20     return 0;
21 }
22 int main()
23 {
24   int i,n,len,flag;
25   gets(s);
26   len= strlen(s);
27   flag=0;
28   for(i=0;i<len;i++)
29   {
30       if(s[i]==n)
31       {
32           continue;
33       }
34       if(!judge(s[i]))
35       {
36           if(i==len-1)
37           {
38               flag=1;
39           }
40           if(s[i+1]==n)
41           {
42               flag=1;
43               break;
44           }
45           else if(!judge(s[i+1]))
46           {
47               flag=1;
48               break;
49           }
50       }
51   }
52   if(!flag)
53   {
54       printf("YES\n");
55   }
56   else
57   {
58       printf("NO\n");
59   }
60   return 0;
61 }

Game Shopping CF1009A

Maxim wants to buy some games at the local game shop. There are nngames in the shop, the ii-th game costs cici.

Maxim has a wallet which can be represented as an array of integers. His wallet contains mm bills, the jj-th bill has value ajaj.

Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.

When Maxim stands at the position ii in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the ii-th game using this bill. After Maxim tried to buy the nn-th game, he leaves the shop.

Maxim buys the ii-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the ii-th game. If he successfully buys the ii-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.

For example, for array c=[2,4,5,2,4] and array a=[5,3,4,6] the following process takes place: Maxim buys the first game using the first bill (its value is 55), the bill disappears, after that the second bill (with value 33) becomes the first one in Maxim‘s wallet, then Maxim doesn‘t buy the second game because c2>a2, the same with the third game, then he buys the fourth game using the bill of value a2 (the third bill becomes the first one in Maxim‘s wallet) and buys the fifth game using the bill of value a3a3.

Your task is to get the number of games Maxim will buy.

Input

The first line of the input contains two integers nn and mm (1n,m1000) — the number of games and the number of bills in Maxim‘s wallet.

The second line of the input contains nn integers c1,c2,,cn(1ci1000), where ci is the cost of the ii-th game.

The third line of the input contains mm integers a1,a2,,am (1aj1000), where aj is the value of the jj-th bill from the Maxim‘s wallet.

Output

Print a single integer — the number of games Maxim will buy.

Examples

Input
5 4
2 4 5 2 4
5 3 4 6
Output
3
Input
5 2
20 40 50 20 40
19 20
Output
0
Input
6 4
4 8 15 16 23 42
1000 1000 1000 1000
Output
4

Note

The first example is described in the problem statement.

In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.

In the third example the values of the bills in Maxim‘s wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.

題目意思:商店裏有n個遊戲,主人公的錢包裏有m張鈔票,之後依次給出每個遊戲的價格和錢包中的鈔票價值。如果當前鈔票價值能買當前遊戲,就會買遊戲用掉鈔票,之後使用下一張鈔票;不能買就換成下一個遊戲,直到能夠買為止,求最多能買多少遊戲。

解題思路:直接模擬就可以了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int c[1010];
 6 int a[1010];
 7 int main()
 8 {
 9     int n,m,i,j;
10     int ans;
11     scanf("%d%d",&n,&m);
12     for(i=1; i<=n; i++)
13     {
14         scanf("%d",&c[i]);
15     }
16     for(i=1; i<=m; i++)
17     {
18         scanf("%d",&a[i]);
19     }
20     i=1;
21     j=1;
22     ans=0;
23     while(i<=n)
24     {
25         if(a[j]>=c[i])
26         {
27             j++;
28             ans++;
29         }
30         if(j==m+1)
31         {
32             break;
33         }
34         i++;
35     }
36     printf("%d\n",ans);
37     return 0;
38 }

Reorder the Array CF 1008C

You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array [10,20,30,40], we can permute it so that it becomes [20,40,10,30]. Then on the first and the second positions the integers became larger (20>10, 40>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 2. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

Input

The first line contains a single integer nn (1n105) — the length of the array.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai109) — the elements of the array.

Output

Print a single integer — the maximal number of the array‘s elements which after a permutation will stand on the position where a smaller element stood in the initial array.

Examples

Input
7
10 1 1 1 5 5 3
Output
4
Input
5
1 1 1 1 1
Output
0

Note

In the first sample, one of the best permutations is [1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

題目意思:給你一個數組,讓你重新排列,使得當前位置的數比原來的數大的位置最多有多少個。

解題思路:這道題應該怎麽想呢?我在看著一道題的時候,突然想到了一個成語,田忌賽馬!和這道題倒是很像,但這是自己的馬之間互相比賽,問最多贏幾場!但這道題還沒有上升到這種博弈的高度,其實換一下思路和好搞,就是看看那些小的數能否換成比它大的數嘛!我開始的想法是將原來數組從大到小排序,看看讓較大的化成較小的,同時用vis數組控制只能交換一次,得到了下面的代碼:

技術分享圖片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int a[100010];
 6 int vis[100010];
 7 int my_cmp(int x,int y)
 8 {
 9     return x>y;
10 }
11 int main()
12 {
13     int n,i,j,ans,flag;
14     scanf("%d",&n);
15     for(i=0;i<n;i++)
16     {
17         scanf("%d",&a[i]);
18     }
19     sort(a,a+n,my_cmp);
20     ans=0;
21     for(i=0;i<n;i++)
22     {
23         flag=0;
24         for(j=i+1;j<n;j++)
25         {
26             if(vis[j])
27             {
28                 continue;
29             }
30             if(a[i]>a[j]&&!vis[j])
31             {
32                 ans++;
33                 flag=1;
34                 vis[j]=1;
35                 break;
36             }
37         }
38         if(!flag)
39         {
40             break;
41         }
42     }
43     printf("%d\n",ans);
44     return 0;
45 }
View Code

但這個代碼效率並不高,其實可以使用雙指針來做。變成從小到大排序,優先使用最小的數進行比較。用兩個指針來遍歷,指針i與指針j,一開始指針i指在第1個數,指針j指在第2個數,如果a[j]>a[i],i指針向後移一位,ans++;否則,i指針還是指在原來的位置;j指針向後移,直到j>n。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int a[100010];
 6 int vis[100010];
 7 int my_cmp(int x,int y)
 8 {
 9     return x>y;
10 }
11 int main()
12 {
13     int n,i,j,ans,flag;
14     scanf("%d",&n);
15     for(i=0;i<n;i++)
16     {
17         scanf("%d",&a[i]);
18     }
19     sort(a,a+n,my_cmp);
20     ans=0;
21     for(i=0;i<n;i++)
22     {
23         flag=0;
24         for(j=i+1;j<n;j++)
25         {
26             if(vis[j])
27             {
28                 continue;
29             }
30             if(a[i]>a[j]&&!vis[j])
31             {
32                 ans++;
33                 flag=1;
34                 vis[j]=1;
35                 break;
36             }
37         }
38         if(!flag)
39         {
40             break;
41         }
42     }
43     printf("%d\n",ans);
44     return 0;
45 }

國慶練習1