ACM:Taurus's Trial(1)

The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it’s easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO

AC:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
	int i = 0,j = 0,k = 0;
	int len1 = 0,len2 = 0;
	int flag = 0;
	char a[106],b[106];
	
		gets(a);
		gets(b);
		len1=strlen(a);
		len2=strlen(b);

		flag=0;
		if(len1!=len2)
		{
			printf("NO\n");
			return 0;
		}
		for(i=0;i<len1;i++)
		{
			if(a[i]!=b[len1-1-i])
			{
				flag=1;
				break;
			}
		}
		if(flag==1)
			printf("NO\n");
		else
			printf("YES\n");
	
	return 0;
}

Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.

If there’s one thing Petya likes more that receiving gifts, that’s watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.

Now Petya wants to know for each friend i the number of a friend who has given him a gift.
Input
The first line contains one integer n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya’s ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output
Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.
Examples
Input
4
2 3 4 1
Output
4 1 2 3
Input
3
1 3 2
Output
1 3 2
Input
2
1 2
Output
1 2

AC:

#include <iostream>
#include<memory.h>
using namespace std;
int main()
{
	int buffa[110] = {0},buffb[110] = {0},n = 0,countnum = 0,i = 0;
	while(cin>>n)
	{

		for(i=0; i<n; i++)
		{
			cin>>buffa[i];
			buffb[buffa[i]]=i+1;
		}
		
		for(i=0; i<110; i++)
		{
			if(buffb[i]!=0)
			{
				if(countnum==n-1)
				{
					cout<<buffb[i]<<endl;
					break;
				}
				cout<<buffb[i]<<" ";
				countnum++;
			}
		}
	}
	return 0;
}

Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that’s why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.

Help Kefa cope with this task!
Input
The first line contains integer n (1 ≤ n ≤ 105).
The second line contains n integers a1,  a2,  …,  an (1 ≤ ai ≤ 109).
Output
Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.
Examples
Input
6
2 2 1 3 4 1
Output
3
Input
3
2 2 9
Output
3
Note
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.

AC:

#include <iostream>
#include <stdio.h>
#include<algorithm>
using namespace std;

const int maxn=1e5+7;
int main()
{
	int n= 0,ans = 0;
	int num[maxn] = {0};
	scanf("%d",&n);
	for(int i=0;i<n;i++) 
		scanf("%d",&num[i]);

	int tmp=1;
	for(int i=1;i<n;i++)
	{
		if(num[i]>=num[i-1]) 
			tmp++;
		else
		{
			ans=max(ans,tmp);
			tmp=1;
		}
	}
	ans=max(ans,tmp);
	printf("%d",ans);
	return 0;
}

Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations ‘+’ and ‘*’, and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let’s consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:

1+2*3=7
1*(2+3)=5
1*2*3=6
(1+2)*3=9

Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.

It’s easy to see that the maximum value that you can obtain is 9.

Your task is: given a, b and c print the maximum value that you can get…
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60

AC:

#include<stdio.h>
#include<algorithm>
#include <iostream>
using namespace std;
int main()
{
	int a = 0,b = 0,c = 0,max_num = 0;
	scanf("%d%d%d",&a,&b,&c);
	
	int buff[4] = {0};
	buff[0]=a+b+c;
	buff[1]=(a+b)*c;
	buff[2]=(b+c)*a;
	buff[3]=a*b*c;
	
	max_num = buff[0];
	for(int i=1;i<4;i++)
		max_num = max(max_num,buff[i]);

	printf("%d",max_num);
	return 0;
}

集训进行了将近2个礼拜,这段时间以恢复性训练为主,我一直在密切关注大家的训练情况,目前为止,对大家的表现相当满意,首先是绝大部分队员的训练积极性很高,其次,都很遵守集训纪律,最后,老队员也起到了很好的带头作用,这里特别感谢为这次DP专题练习赛提供题目和测试数据的集训队队长xhd同学.

特别高兴的是,跟随集训队训练的一批新队员表现非常好,进步也比较显著,特别是训练态度大大超出我的预期,我敢说,如果各位能如此坚持下去,绝对前途无量!

考虑到新队员还没有经过系统训练,我这里特别添加一道简单题:
给定三个正整数A,B和C(A,B,C<=1000000),求A^B mod C的结果.

希望各位都能体会到比赛中AC的快乐,绝对的量身定制,很高的待遇哟,呵呵…

Input
输入数据首先包含一个正整数N,表示测试实例的个数,然后是N行数据,每行包括三个正整数A,B,C。
Output
对每个测试实例请输出计算后的结果,每个实例的输出占一行。
Sample Input
3
2 3 4
3 3 5
4 4 6
Sample Output
0
2
4

AC:

#include<stdio.h>
#include<string.h>
#include<math.h>

long long  PowerMod (long long a, long long b, long long c) 
{  
	int  ans = 1; 
	a = a % c; 
	while(b>0) 
	{  
		if(b % 2 == 1) 
			ans = (ans * a) % c; 
		b = b/2;       
		a = (a * a) % c; 
	} 
	return ans; 
}  

int main()
{
	int total = 0,i = 1,j = 0;
	 long long n = 0,ci = 0,mo = 0;
	 long long ans = 1;
	
	scanf("%d",&total);
	for(j = 0;j < total;j ++)
	{
		scanf("%d%d%d",&n,&ci,&mo);
		ans = PowerMod(n,ci,mo);
		printf("%d\n",ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值