[HDU]ACM Steps-Chapter One-Section 2
2016-03-09 21:08
405 查看
1.2.1
给定直径(英寸)、转数、时间(秒)。直径是用英寸表示作为一个浮点值
输出距离(英里)、英里/每小时
一英里有5280英尺。一英尺有12英寸。
#include <stdio.h>
int main()
{
float diameter;
int revolutions;
float time;
int sum = 0;
while (scanf("%f %d %f", &diameter, &revolutions, &time) && revolutions != 0)
{
float distance = 0;
distance=diameter*3.1415927*revolutions/ 5280/12;
time /= 3600;
float MPH;
MPH = distance / time;
printf("Trip #%d: %.2f %.2f\n", ++sum, distance ,MPH);
}
}
1.2.2
实际上为求N和M是否互质。用辗转相除法。
#include<stdio.h>
int main()
{
int m, n;
int r;
while (scanf("%d %d", &n, &m) && m != -1 && n != -1)
{
while (n%m != 0)
{
r = n%m;
n = m;
m = r;
}
if (m == 1)
printf("YES\n");
else
printf("POOR Haha\n");
}
return 0;
}
1.2.3
#include<stdio.h>
int main()
{
int a[100], i;
int sum = 0, num = 1, res = 0, sum2 = 0;
scanf("%d", &sum);
while (sum != 0)
{
sum2 = 0;
for (i = 0; i < sum; i++)
{
scanf("%d", &a[i]);
sum2 += a[i];
}
sum2 /= sum;
res = 0;
for (i = 0; i < sum; i++)
{
if (a[i] > sum2)
res += (a[i] - sum2);
}
printf("Set #%d\n", num);
printf("The minimum number of moves is %d.\n\n", res);
num++;
scanf("%d", &sum);
}
return 0;
}
1.2.4
#include <stdio.h>
#include <string.h>
int main()
{
char a[10000];
int i,s,w,sum=0;
while (gets(a),a[0]!='#')
{
sum=0;
s=strlen(a);
for(i=0,w=1; i<s; w++,i++)
{
if(a[i]==' ')sum+=0;
else sum+=(a[i]-64)*w;
}
printf("%d\n",sum);
}
}
1.2.5
#include <stdio.h>
int main()
{
int a[3], n, x, y;
scanf("%d", &n);
while (n--)
{
int tem;
scanf("%d %d %d", &a[0], &a[1], &a[2]);
for (x = 0; x < 2; x++)
for (y = 0; y < 2 - x; y++)
if (a[y]>a[y + 1])
{
tem = a[y];
a[y] = a[y + 1];
a[y + 1] = tem;
}
if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2])printf("good\n");
else if (a[0] == a[1] || a[2] == a[1])printf("perfect\n");
else printf("just a triangle\n");
}
return 0;
}
1.2.6
#include <stdio.h>
#include <string.h>
int k = 1;
int main()
{
char a[100];
int s, i, m, w;
scanf("%d\n", &s);
for (m = 0; m < s; m++)
{
gets(a);
w = strlen(a);
for (i = 0; i < w; i++)
{
if (a[i] >= 'A'&&a[i] <= 'Y')a[i] = (a[i] + 1);
else if (a[i] == 'Z')a[i] = 'A';
}
printf("String #%d\n", k);
k++;
puts(a);
if (m <= (s - 1))printf("\n");
}
return 0;
}
1.2.7
#include<stdio.h>
#include<math.h>
int main()
{
int a;
scanf("%d", &a);
while (a != 0)
{
int b, d = 0, i = 0, max, m, n, sum = 0;
int shuzu[100], shuzu2[100], res[100];
while (a != 0)
{
shuzu[i] = a % 2;
a /= 2;
i++;
}
i = 0;
while (shuzu[i] != 1)
{
res[i] = 0;
i++;
}
res[i] = 1;
max = i + 1;
for (i = 0, sum = 0; i < max; i++)
{
sum += (res[i] * pow(2, i));
}
printf("%d\n", sum);
scanf("%d", &a);
}
return 0;
}
1.2.8
#include<stdio.h>
#include<string.h>
char save[100009];
int main()
{
while (gets(save))
{
int l[27];
int i = 0;
for (i = 0; i < 26; i++)
l[i] = 0;
for (i = 0; i < strlen(save); i++)
l[save[i] - 'a']++;
for (i = 0; i < 26; i++)
printf("%c:%d\n", 'a' + i, l[i]);
printf("\n");
}
return 0;
}
Problem Description Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attached to one of the spokes on the front wheel so that it will line up with the Hall Effect switch once per revolution of the wheel. The speedometer monitors the sensor to count wheel revolutions. If the diameter of the wheel is known, the distance traveled can be easily be calculated if you know how many revolutions the wheel has made. In addition, if the time it takes to complete the revolutions is known, the average speed can also be calculated. For this problem, you will write a program to determine the total distance traveled (in miles) and the average speed (in Miles Per Hour) given the wheel diameter, the number of revolutions and the total time of the trip. You can assume that the front wheel never leaves the ground, and there is no slipping or skidding. |
Input Input consists of multiple datasets, one per line, of the form: diameter revolutions time The diameter is expressed in inches as a floating point value. The revolutions is an integer value. The time is expressed in seconds as a floating point value. Input ends when the value of revolutions is 0 (zero). |
Output For each data set, print: Trip #N: distance MPH Of course N should be replaced by the data set number, distance by the total distance in miles (accurate to 2 decimal places) and MPH by the speed in miles per hour (accurate to 2 decimal places). Your program should not generate any output for the ending case when revolutions is 0. Constants For p use the value: 3.1415927. There are 5280 feet in a mile. There are 12 inches in a foot. There are 60 minutes in an hour. There are 60 seconds in a minute. There are 201.168 meters in a furlong. |
Sample Input26 1000 5 27.25 873234 3000 26 0 1000 |
Sample OutputTrip #1: 1.29 928.20 Trip #2: 1179.86 1415.84 |
输出距离(英里)、英里/每小时
一英里有5280英尺。一英尺有12英寸。
#include <stdio.h>
int main()
{
float diameter;
int revolutions;
float time;
int sum = 0;
while (scanf("%f %d %f", &diameter, &revolutions, &time) && revolutions != 0)
{
float distance = 0;
distance=diameter*3.1415927*revolutions/ 5280/12;
time /= 3600;
float MPH;
MPH = distance / time;
printf("Trip #%d: %.2f %.2f\n", ++sum, distance ,MPH);
}
}
1.2.2
Problem Description The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. Now I introduce the game to you. Suppose there are N people played the game ,who sit on the ground forming a circle ,everyone owns a box behind them .Also there is a beautiful handkerchief hid in a box which is one of the boxes . Then Haha(a friend of mine) is called to find the handkerchief. But he has a strange habit. Each time he will search the next box which is separated by M-1 boxes from the current box. For example, there are three boxes named A,B,C, and now Haha is at place of A. now he decide the M if equal to 2, so he will search A first, then he will search the C box, for C is separated by 2-1 = 1 box B from the current box A . Then he will search the box B ,then he will search the box A. So after three times he establishes that he can find the beautiful handkerchief. Now I will give you N and M, can you tell me that Haha is able to find the handkerchief or not. If he can, you should tell me "YES", else tell me "POOR Haha". |
Input There will be several test cases; each case input contains two integers N and M, which satisfy the relationship: 1<=M<=100000000 and 3<=N<=100000000. When N=-1 and M=-1 means the end of input case, and you should not process the data. |
Output For each input case, you should only the result that Haha can find the handkerchief or not. |
Sample Input3 2 -1 -1 |
Sample OutputYES |
#include<stdio.h>
int main()
{
int m, n;
int r;
while (scanf("%d %d", &n, &m) && m != -1 && n != -1)
{
while (n%m != 0)
{
r = n%m;
n = m;
m = r;
}
if (m == 1)
printf("YES\n");
else
printf("POOR Haha\n");
}
return 0;
}
1.2.3
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. “Look, I\'ve built a wall!”, he tells his older sister Alice. “Nah, you should make all stacks the same height. Then you would have a real wall.”, she retorts. After a little consideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help? |
Input The input consists of several data sets. Each set begins with a line containing the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1≤n≤50 and 1≤hi≤100. The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height. The input is terminated by a set starting with n = 0. This set should not be processed. |
Output For each set, print the minimum number of bricks that have to be moved in order to make all the stacks the same height. Output a blank line between each set. |
Sample Input6 5 2 4 1 7 5 0 |
Sample OutputSet #1 The minimum number of moves is 5. |
int main()
{
int a[100], i;
int sum = 0, num = 1, res = 0, sum2 = 0;
scanf("%d", &sum);
while (sum != 0)
{
sum2 = 0;
for (i = 0; i < sum; i++)
{
scanf("%d", &a[i]);
sum2 += a[i];
}
sum2 /= sum;
res = 0;
for (i = 0; i < sum; i++)
{
if (a[i] > sum2)
res += (a[i] - sum2);
}
printf("Set #%d\n", num);
printf("The minimum number of moves is %d.\n\n", res);
num++;
scanf("%d", &sum);
}
return 0;
}
1.2.4
Problem Description A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data. For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces. A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "ACM" and "MID CENTRAL": ACM: 1*1 + 2*3 + 3*13 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650 |
Input The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters. |
Output For each packet, output its Quicksum on a separate line in the output. |
Sample InputACM MID CENTRAL REGIONAL PROGRAMMING CONTEST ACN A C M ABC BBC # |
Sample Output46 650 4690 49 75 14 15 |
#include <string.h>
int main()
{
char a[10000];
int i,s,w,sum=0;
while (gets(a),a[0]!='#')
{
sum=0;
s=strlen(a);
for(i=0,w=1; i<s; w++,i++)
{
if(a[i]==' ')sum+=0;
else sum+=(a[i]-64)*w;
}
printf("%d\n",sum);
}
}
1.2.5
Problem Description This is an easy problem, just for you to warm up. Give you three edges of a triangle. Can you tell me which kind of triangle it stands for? If it’s a right triangle(直角三角形), please output “good”. If it’s a isosceles triangle(等腰三角形), please output “perfect”. Otherwise, please output “just a triangle”. You may suppose the input is legal. |
Input The first line contains an integer t means the number of test cases. The each case contains three integers a, b, c in a line which stands for the length of the three edges. (0 <a, b, c < 300). |
Output For each case, output the answer in one line. |
Sample Input4 3 4 5 2 2 3 1 4 4 4 6 3 |
Sample Outputgood perfect perfect just a triangle |
int main()
{
int a[3], n, x, y;
scanf("%d", &n);
while (n--)
{
int tem;
scanf("%d %d %d", &a[0], &a[1], &a[2]);
for (x = 0; x < 2; x++)
for (y = 0; y < 2 - x; y++)
if (a[y]>a[y + 1])
{
tem = a[y];
a[y] = a[y + 1];
a[y + 1] = tem;
}
if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2])printf("good\n");
else if (a[0] == a[1] || a[2] == a[1])printf("perfect\n");
else printf("just a triangle\n");
}
return 0;
}
1.2.6
Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only two men are awake, and the ship is controlled by the intelligent computer HAL. But during the flight HAL is acting more and more strangely, and even starts to kill the crew on board. We don't tell you how the story ends, in case you want to read the book for yourself :-) After the movie was released and became very popular, there was some discussion as to what the name 'HAL' actually meant. Some thought that it might be an abbreviation for 'Heuristic ALgorithm'. But the most popular explanation is the following: if you replace every letter in the word HAL by its successor in the alphabet, you get ... IBM. Perhaps there are even more acronyms related in this strange way! You are to write a program that may help to find this out. |
Input The input starts with the integer n on a line by itself - this is the number of strings to follow. The following n lines each contain one string of at most 50 upper-case letters. |
Output For each string in the input, first output the number of the string, as shown in the sample output. The print the string start is derived from the input string by replacing every time by the following letter in the alphabet, and replacing 'Z' by 'A'. Print a blank line after each test case. |
Sample Input2 HAL SWERC |
Sample OutputString #1 IBM String #2 TXFSD |
#include <string.h>
int k = 1;
int main()
{
char a[100];
int s, i, m, w;
scanf("%d\n", &s);
for (m = 0; m < s; m++)
{
gets(a);
w = strlen(a);
for (i = 0; i < w; i++)
{
if (a[i] >= 'A'&&a[i] <= 'Y')a[i] = (a[i] + 1);
else if (a[i] == 'Z')a[i] = 'A';
}
printf("String #%d\n", k);
k++;
puts(a);
if (m <= (s - 1))printf("\n");
}
return 0;
}
1.2.7
Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. For example, given A = 26, we can write A in binary form as 11010, so the lowest bit of A is 10, so the output should be 2. Another example goes like this: given A = 88, we can write A in binary form as 1011000, so the lowest bit of A is 1000, so the output should be 8. |
Input Each line of input contains only an integer A (1 <= A <= 100). A line containing "0" indicates the end of input, and this line is not a part of the input data. |
Output For each A in the input, output a line containing only its lowest bit. |
Sample Input26 88 0 |
Sample Output2 8 |
#include<math.h>
int main()
{
int a;
scanf("%d", &a);
while (a != 0)
{
int b, d = 0, i = 0, max, m, n, sum = 0;
int shuzu[100], shuzu2[100], res[100];
while (a != 0)
{
shuzu[i] = a % 2;
a /= 2;
i++;
}
i = 0;
while (shuzu[i] != 1)
{
res[i] = 0;
i++;
}
res[i] = 1;
max = i + 1;
for (i = 0, sum = 0; i < max; i++)
{
sum += (res[i] * pow(2, i));
}
printf("%d\n", sum);
scanf("%d", &a);
}
return 0;
}
1.2.8
Problem Description Ignatius is doing his homework now. The teacher gives him some articles and asks him to tell how many times each letter appears. It's really easy, isn't it? So come on and AC ME. |
Input Each article consists of just one line, and all the letters are in lowercase. You just have to count the number of each letter, so do not pay attention to other characters. The length of article is at most 100000. Process to the end of file. Note: the problem has multi-cases, and you may use "while(gets(buf)){...}" to process to the end of file. |
Output For each article, you have to tell how many times each letter appears. The output format is like "X:N". Output a blank line after each test case. More details in sample output. |
Sample Inputhello, this is my first acm contest! work hard for hdu acm. |
Sample Outputa:1 b:0 c:2 d:0 e:2 f:1 g:0 h:2 i:3 j:0 k:0 l:2 m:2 n:1 o:2 p:0 q:0 r:1 s:4 t:4 u:0 v:0 w:0 x:0 y:1 z:0 a:2 b:0 c:1 d:2 e:0 f:1 g:0 h:2 i:0 j:0 k:1 l:0 m:1 n:0 o:2 p:0 q:0 r:3 s:0 t:0 u:1 v:0 w:1 x:0 y:0 z:0 |
#include<string.h>
char save[100009];
int main()
{
while (gets(save))
{
int l[27];
int i = 0;
for (i = 0; i < 26; i++)
l[i] = 0;
for (i = 0; i < strlen(save); i++)
l[save[i] - 'a']++;
for (i = 0; i < 26; i++)
printf("%c:%d\n", 'a' + i, l[i]);
printf("\n");
}
return 0;
}
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points