UCF Local Programming Contest 2014(Practice)补题/赛后

A. How Sweet It Is!

Dr. Orooji’s twins, Mack and Zack, love video games. We will assume that all games are 50. M/Z save all the money they get and, when they have50.M/Zsaveallthemoneytheygetand,whentheyhave50 or more, they buy a game and say “Sweet!” out of happiness. If M/Z get a large amount of money at one time (e.g., on their birthday) and they can buy two or more games, they buy two or more games (as many as they can) and say “Totally Sweet!” since they are really in heaven! When M/Z buy game(s), they save the left-over money towards the next purchase.

The Problem:

Given the money (various amounts) M/Z receive, you are to write a program to tell Dr. O when Sweet or Totally Sweet is coming.

The Input:

Each input line contains a positive integer, indicating an amount M/Z are receiving. End-of-data is indicated with a zero.

The Output:

Print the input line numbers and the messages they generate. Follow the format illustrated in Sample Output.

样例输入

10
20
30
10
90
10
10
30
0

样例输出

Input #3: Sweet!
Input #5: Totally Sweet!
Input #8: Sweet!

题解

模拟,一直收钱,当前的钱额超过50就花掉50,能买一个玩具就Sweet! 能买多个就Totally Sweet!

#include<stdio.h>
int main()
{
   
	int a,sum=0,cas=1;
	while(~scanf("%d",&a))
	{
   
		if(a==0)
		break;
		sum+=a;
		if(sum/50==1)
		{
   
			printf("Input #%d: Sweet!\n",cas);
			sum-=50;			
		}
		else if(sum/50>=2)
		{
   
			printf("Input #%d: Totally Sweet!\n",cas);
			int n=sum/50;
			sum-=50*n;	
		}
		cas++;		
	}
	return 0;
}

B. Wheel of Universally Copious Fortune

In the game “Wheel of Fortune”, the number of letters in a word is given and the contestants guess the letters in the word and, as some letters appear, the contestants guess the word. But, you are a computer scientist and know that you can write a program to search a dictionary and provide candidate words (possible matches) for you.

The Problem:

Given the dictionary and a partially-defined word, you are to determine the candidate words. Note that there may be no candidate words for a given partially-defined word.

The Input:

The first input line contains an integer n (1 ≤ n ≤ 100), indicating the number of words in the dictionary. The dictionary words will be on the following n input lines, one word per line. Each word starts in column 1, contains only lowercase letters, and will be 1-20 letters (inclusive). Assume that the dictionary words are distinct, i.e., no duplicates. The next input line will contain a positive integer m, indicating the number of words to be checked against the dictionary. These words will be on the following m input lines, one word per line. Each word starts in column 1, contains only lowercase letters and hyphens, and will be 1-20 characters (inclusive). A letter in a position indicates that the word must have that letter in that position; a hyphen in a position indicates that any letter can be in that position.

The Output:

At the beginning of each word to be checked, output “Word #w:”, where w is the word number (starting from 1). Then print the input word to be checked. Then, on the following output lines, print the candidate words from dictionary that could be a match (print these words in the order they appear in the dictionary). Also print the total number of candidate words (possible matches).

Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.

样例输入

8
at
cat
ali
sat
nerds
coach
couch
ninja
5
co-ch
-at

ali
a-c

样例输出

Word #1: co-ch
coach
couch
Total number of candidate words = 2

Word #2: -at
cat
sat
Total number of candidate words = 2

Word #3: —
cat
ali
sat
Total number of candidate words = 3

Word #4: ali
ali
Total number of candidate words = 1

Word #5: a-c
Total number of candidate words = 0

题解

字符串匹配。

#include<iostream>
#include<string>
using namespace std;
int compare(string &strS, string &strT, int i, int j)
{
   
	if(i>=strS.size())
	{
   
		if(j>=strT.size())
			return 1;
		return 0;
	}
	if(strS[i]==strT[j]||strT[i]=='-')
		return compare(strS, strT, i+1, j+1);
	return 0;
}
int main()
{
   
	string  p[105],s,t;
	int n,m,cas=1,cnt;
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>p[i];
	cin>>m;
	while(m--)
	{
   
		cnt=0;
		cin>>t;
		printf("Word #%d: ",cas++);
		cout<<t<<endl;
		for(int i=1; i<=n; i++)
		{
   
			s=p[i];
			if(compare(s,t,0,0))
			{
   
				cout<<s<<endl;
				cnt++;
			}
		}
		printf("Total number of candidate words = %d\n",cnt);
		cout<<endl;
	}
	return 0;
}

C. Positively Pentastic!

Five random integers are placed at the corners of a pentagon. Typically, some of these numbers will be negative, but their sum is guaranteed to be positive. The goal is to get rid of all the negative numbers through a balanced process of subtraction and negation.

Starting with the lowest of the negative numbers, we negate the number (thus making it positive), and then subtract that value from each of its two neighbors. The sum of the new numbers will remain the same as the original pentagon, so the pentagon is still “balanced.” This process (finding the lowest of the negative numbers, negating it, and subtracting it from its neighbors) is then repeated until all of the numbers are non-negative.image.pngDuring any step, if the lowest negative number appears at more than one corner, use the one that would be found first, if you started at the top corner and traversed in clockwise direction.

The Problem:

Given the original five numbers at the corners of a pentagon, output the Positive Pentagon that can be created by following this process. You may assume this process will always make a pentagon “pentastic” in at most 1000 steps.

The Input:

The first input line will contain only a single positive integer N, which is the number of pentagons to process. The next N lines will contain pentagon descriptions, one per line. Each pentagon description will consist of exactly 5 integers, which are in the range -999 to 999 (inclusive), and which sum up to a positive number less than 1000.

There will be exactly one space between numbers, and no leading or trailing spaces on the input lines. Positive numbers in the input will not have a leading ‘+’ sign. The numbers are given in a clockwise order around the pentagon, starting from the top. This means that the 1 ^ st and 3 ^ rd numbers are neighbors of the 2^ nd number, the 5 ^ th and 2 ^ nd numbers are neighbors of the 1 ^ st number, and so on.

The Output:

For each pentagon in the input, output the message “Pentagon #p:”, where p is the pentagon number (starting from 1). Then, for each pentagon, output the Positive Pentagon that results from applying the process described above. Output the numbers for each corner using the same ordering and method used in the input, with number for the top corner first, and the others following a clockwise order. Output one space between output numbers.

Leave a blank line after the output for each test case. Follow the format illustrated in the Sample Output.

样例输入

2
2 -1 5 7 -4
99 -1 -1 4 0

样例输出

Pentagon #1:
1 2 2 3 1

Pentagon #2:
97 1 1 2 0

题解

模拟,直到最小的数为非负数。

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[5],b[5];
int cmp(int x, int y)
{
   
	return a[x]<a[y];
}
int main()
{
   
	int n,cas=1;
	scanf("%d",&n);
	for(int i=0; i<5; i++)
		b[i]=i;
	while(n--)
	{
   
		for(int i=0; i<5; i++)
			scanf("%d",&a[i]);
		while(1)
		{
   
			sort(b,b+5,cmp);
			if(a[b[0]]>=0) break;			
			a[(b[0]-1+5)%5]+=a[b[0]];
			a[(b[0]+1)%5]+=a[b[0]];
			a[b[0]]=-a[b[0]];
		}
		printf
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值