国庆练习1(代码片段)

wkfvawl wkfvawl     2023-01-05     269

关键词:

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
");
55   
56   else
57   
58       printf("NO
");
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
",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>1040>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
",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
",ans);
44     return 0;
45 

 

国庆练习3(代码片段)

BenchesCF1042AThereare nn benchesintheBerlandCentralpark.Itisknownthat aiai peoplearecurrentlysittingonthe ii-thbench.Another mm peoplearecomingtotheparkandeachofthe 查看详情

国庆练习2(代码片段)

Equality CF1038AA subsequence ofstring ss isastringthatcanbederivedfrom ssbydeletingsomeofitssymbolswithoutchangingtheorderoftheremainingsymbols.Forexample,"ADE"and"BD"ar 查看详情

国庆练习4(代码片段)

LittleCLoves3IDescriptionLittleClovesnumber«3»verymuch.Helovesallthingsaboutit.Nowhehasapositiveinteger nn.Hewantstosplit nn into 33 positiveintegers a,b,ca,b 查看详情

国庆5(代码片段)

Codeforces1060b Youaregivenapositiveinteger nn.Let S(x)S(x) besumofdigitsinbase10representationof xx,forexample, S(123)=1+2+3=6S(123)=1+2+3=6, S(0)=0S(0)=0.Yourtaski 查看详情

汇思学18国庆图论(代码片段)

      图论1.基本概念        2.图的储存  3.路径  4.自由树  5.有根树和二叉树  6.图的遍历  7.连通  8.拓扑排序  9.欧拉路径  10.最短路    (1)Dijkstra  voiddijkstra(intx)for(inti=1;i<... 查看详情

汇思学18国庆数论(代码片段)

      数论1.快速幂typedeflonglongLL;LLqpow(inta,intb)//快速幂LLres=1;while(b)if(b&1)res=res*a%p;a=a*a%p;b>>=1;returnres;LLmul(inta,intb)//快速乘LLres=0;while(b)if(b&1)res=(res+a)%p;a=(a+a)%p; 查看详情

10.2正睿国庆集训测试1(代码片段)

目录2018..Test总结A陈太阳与取模B陈太阳与路径(树形DP)C陈太阳与开关考试代码BC2018..Test时间:3.5h期望得分:100+50+20实际得分:40+45+20比赛链接总结感觉自己是个zzA陈太阳与取模题目链接[eginalignedc\%x&equiv(c\%A)\%x\c\%x&equiv(c-lflo... 查看详情

pythonpython练习-练习1(rrosinante)(代码片段)

查看详情

java基础语法学会异常处理,祝你国庆快乐(代码片段)

前言:前些章节的知识点有时会涉及到异常的知识,如果没有专门学习过异常的小伙伴可能看的有点疑惑。今天这节就是为了讲解异常,让我们来了解什么是异常,它的作用是啥,怎么使用异常。文章目录1.异... 查看详情

国庆福利“css定位大礼包”(代码片段)

...偏移总结喜提大礼包小编我恭喜你抽中了我为你们准备的国庆前夕大礼包,这个大礼包就是CSS定位知识点大礼包,你开不开心,意不意外 查看详情

国庆七天乐leetcode算法14天集训营题解(1~7天)(代码片段)

国庆正好空闲,想着好久没有刷题了(太懒),应该push自己一点,那就看看简单的算法集训营吧~在数学和计算机科学之中,算法是一个被定义好的、计算机可施行之指示的有限步骤或次序,常用于计算、数据处... 查看详情

10.06国庆节第九场模拟赛(代码片段)

密钥(key)Description在这个问题中,一个密钥是指一个长度为(3n)的二进制序列,其中(n)是正整数。序列的每一位从左往右依次被编号为(1)到(3n),一个密钥的权值是指数字不同的相邻位的个数再加上(1)。比如:(000)的权值是(1),(011010... 查看详情

text对象练习1(代码片段)

查看详情

10.3国庆作业(uart实验)(代码片段)

文章目录作业内容思路分析1.电路分析RCC章节分析GPIO章节分析UART章节代码实现uart4.huart4.cmain.c测试结果作业内容完成UART实验:实现串口工具输入一个字符串,按下回车键,会显示输入的字符串思路分析1.电路分析通过... 查看详情

10-4国庆节第七场模拟赛题解(代码片段)

10-4国庆节第七场模拟赛题解T1工厂(factory)水#include<iostream>#include<cstdio>#defineintlonglongusingnamespacestd;inlineintread()intsum=0,f=1;charch=getchar();while(ch<'0'||ch>'9') 查看详情

html目标练习1开始(代码片段)

查看详情

数据的存储练习题(代码片段)

练习练习一练习二练习三练习四练习五练习六练习七练习一1.//输出什么?#include<stdio.h>intmain()chara=-1;signedcharb=-1;unsignedcharc=-1;printf("a=%d,b=%d,c=%d",a,b,c);return0;  输出结果为-1-12 查看详情

这个国庆,我们结婚了(代码片段)

新郎:叶金辉新娘:林霄   浙江医药高等专科学校医疗器械学院医疗器械维护与管理(检验与注册)D16级学生   2015年8月我们第一次组队参加智能车比赛。我们从第十届全国大学生“飞思卡尔”杯智能汽车... 查看详情