UVA 初学者题目

来源:互联网 发布:什么电脑壁纸软件好 编辑:程序博客网 时间:2024/05/19 10:37

原题:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996

Problem A

Hashmat the brave warrior

Input: standard input

Output: standard output

 

Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to fight against his opponents. Before fighting he just calculates one thing, the difference between his soldier number and the opponent's soldier number. From this difference he decides whether to fight or not. Hashmat's soldier number is never greater than his opponent.


Input

The input contains two integer numbers in every line. These two numbers in each line denotes the number of soldiers in Hashmat's army and his opponent's army or vice versa. The input numbers are not greater than 2^32. Input is terminated by End of File.

 

Output

 For each line of input, print the difference of number of soldiers between Hashmat's army and his opponent's army. Each output should be in seperate line.

 

Sample Input:

10 12
10 14
100 200

 

Sample Output:

2
4
100

#include <stdio.h>/*author:Yangsirtime:2014/5/7*/int main(){long long a,b;while(~scanf("%lld%lld",&a,&b))printf("%lld\n",a>b?a-b:b-a);return 0;}
原题:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=1012

Problem B

Back to High School Physics

Input: standard input

Output: standard output

 

A particle has initial velocity and constant acceleration. If its velocity after certain time is v then what will its displacement be in twice of that time?

 

Input

The input will contain two integers in each line. Each line makes one set of input. These two integers denote the value of v (-100 <= v <= 100) and t(0<=t<= 200) ( t means at the time the particle gains that velocity) 

 

Output

For each line of input print a single integer in one line denoting the displacement in double of that time.

 

Sample Input

0 0
5 12

Sample Output

0
120
AC代码:
#include <stdio.h>/*author:Yangsirtime:2014/5/7*/int main(){int v,t;while(~scanf("%d%d",&v,&t))printf("%d\n",2*v*t);return 0;}


原题:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=1241

Problem A

Ecological Premium

Input: standard input

Output: standard output

Time Limit: 1 second

Memory Limit: 32 MB

German farmers are given a premium depending on the conditions at their farmyard. Imagine the following simplified regulation: you know the size of each farmer's farmyard in square meters and the number of animals living at it. We won't make a difference between different animals, although this is far from reality. Moreover you have information about the degree the farmer uses environment-friendly equipment and practices, expressed in a single integer greater than zero. The amount of money a farmer receives can be calculated from these parameters as follows. First you need the space a single animal occupies at an average. This value (in square meters) is then multiplied by the parameter that stands for the farmer's environment-friendliness, resulting in the premium a farmer is paid per animal he owns. To compute the final premium of a farmer just multiply this premium per animal with the number of animals the farmer owns.

Input

The first line of input contains a single positive integer n (<20), the number of test cases. Each test case starts with a line containing a single integer f (0<f<20), the number of farmers in the test case. This line is followed by one line per farmer containing three positive integers each: the size of the farmyard in square meters, the number of animals he owns and the integer value that expresses the farmer’s environment-friendliness. Input is terminated by end of file. No integer in the input is greater than 100000 or less than 0.

 

Output

For each test case output one line containing a single integer that holds the summed burden for Germany's budget, which will always be a whole number. Do not output any blank lines.

 

Sample Input

3
5
1 1 1
2 2 2
3 3 3
2 3 4
8 9 2
3
9 1 8
6 12 1
8 1 1
3
10 30 40
9 8 5
100 1000 70

Sample Output

38

86

7445


AC代码:

#include <stdio.h>/*author:YangSirtime:2014/5/7*/int main(){int n,f,i,a,b,c,sum;while (~scanf("%d",&n)){while(n--){scanf("%d", &f);sum=0;for (i=0;i<f;i++){scanf("%d%d%d",&a,&b,&c);sum+=a*c;}printf("%d\n",sum);}}return 0;}


0 0
原创粉丝点击