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 s is Berlanese.
Input
The first line of the input contains the string 1≤|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
sumimasen
YES
ninja
YES
codeforces
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 ci.
Maxim has a wallet which can be represented as an array of integers. His wallet contains aj.
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 n-th game, he leaves the shop.
Maxim buys the (this bill still remains the first one) and proceeds to the next game.
For example, for array a3.
Your task is to get the number of games Maxim will buy.
Input
The first line of the input contains two integers ) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains i-th game.
The third line of the input contains j-th bill from the Maxim's wallet.
Output
Print a single integer — the number of games Maxim will buy.
Examples
5 4
2 4 5 2 4
5 3 4 6
3
5 2
20 40 50 20 40
19 20
0
6 4
4 8 15 16 23 42
1000 1000 1000 1000
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 . 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 ) — the length of the array.
The second line contains ) — 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
7
10 1 1 1 5 5 3
4
5
1 1 1 1 1
0
Note
In the first sample, one of the best permutations is . 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 }