当前位置:文档之家› 杭电ACM水题题目及代码

杭电ACM水题题目及代码

Total Submission(s) : 65 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
scanf("%s",str2);
len_str2 = strlen(str2);
for(i = 0; i <= len_str2 - 1; ++i)
b[i] = str2[len_str2 - 1 - i] - '0';
if(len_str1 > len_str2)
len_max = len_str1;
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 69615 Accepted Submission(s): 12678
Problem Description
sum2 = 0;
if(x > y)
{
temp = x;
x = y;
y = temp;
}
for(; x <= y; x++)
{
if( x % 2 == 0)
{
sum1 += x * x;
}
else
sum2 += x * x * x;
}
printf("%d %d\n", sum1, sum2);
}
return 0;
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Author
Ignatius.L
#include <stdio.h>
#include <string.h>
int main(){
char str1[1001], str2[1001];
int t, i, len_str1, len_str2, len_max, num = 1, k;
scanf("%d", &t);
count++;
}
}
if(count == 0)
printf("no\n");
else
printf("\n");
}
return 0;
}
2012素数判定
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Output
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120
300 380
{
k1 = m / 100;
k2 = (m - 100 * k1) / 10;
k3 = (m -100 * k1 -10 * k2);
if(m == k1*k1*k1 + k2*k2*k2 + k3*k3*k3)
{
if(count != 0)
{
printf(" ");
}
printf("%d", m);
Font Size: ← →
Problem Description
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
num++;
printf("%s + %s = ", str1, str2);
if(c[len_max] == 1)
printf("1");
for(i = len_max - 1; i >= 0; --i){
printf("%d", c[i]);
}
printf("\n");
if(t >= 1)
printf("\n");
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
lcy
Source
C语言程序设计练习(二)
Statistic|Submit|Back
#include <stdio.h>
int main()
{
int x, y, sum, i, count, n;
while(scanf("%d %d", &x, &y) != EOF && (x!=0 || y!= 0))
Sample Input
56
67
100
123
Sample Output
E
D
A
Score is error!
Author
lcy
Source
C语言程序设计练习(一)
Recommend
JGShining
#include <stdio.h>
int main(){
int n, k;
while(scanf("%d", &n) != EOF){
1001
#include <stdio.h>
int main()
{
int i,a,j;double sum;
while(scanf("%d",&a)!=EOF)
{
sum=0;
for(j=1;j<=a;j++)
{
sum+=j;
}
printf("%.0lf\n\n",sum);
}
return 0;
}
1002A + B Problem II
else
len_max = len_str2;
k = 0;
for(i = 0; i <= len_max - 1; ++i){
c[i] = (a[i] + b[i] + k) % 10;
k = (a[i] + b[i] + k) / 10;
}
if(k != 0)
c[len_max] = 1;
printf("Case %d:\n", num);
Input
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK
Author
if(n < 0 || n >100)
printf("Score is error!\n");
相关主题