杭电ACM水题题目及代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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);
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
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK
Author
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){
}
2010水仙花数
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 144 Accepted Submission(s) : 27
Font: Times New Roman | Verdana | Georgia
getchar();
while(t--){
int a[1001] = {0}, b[1001] = {0}, c[1001] = {0};
scanf("%s", str1);
len_str1 = strlen(str1);
for(i = 0; i <= len_str1 - 1; ++i)
a[i] = str1[len_str1 - 1 - i] - '0';
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);
Sample Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
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.
if(n < 0 || n >100)
printf("Score is error!\n");
else{
k = n / 10;
switch(k){
case 10: printf("A\n"); break;
case 9: printf("A\n"); break;
case 8: printf("B\n"); break;
}
return 0;
}
成绩转换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25250 Accepted Submission(s): 10776
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))
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");
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)
Sample Output
no
370 371
Author
lcy
Source
C语言程序设计练习(二)
#include <stdio.h>
int main()
{
int m, n, k1, k2, k3, count;
while(scanf("%d %d", &m, &n) != EOF)
{
for(count = 0; m <= n; ++m)
4 28
20 152
Author
lcy
Source
C语言程序设计练习(一)
Statistic|
#include <stdio.h>
int main()
{
int x , y, temp, sum1, sum2;
while(scanf("%d %d", &x, &y) != EOF)
{
sum1 = 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.
Font Size: ← →
Problem Description
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
Total Submission(s) : 65 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
Problem Description
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
Input
输入数据有多组,每组占一行,由一个整数组成。
Output
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
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;
case 7: printf("C\n"); break;
case 6: printf("D\n"); break;
default: printf("E\n"); break;
}
}
}
return 0;
}
2007平方和与立方和
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Output
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120
300 380
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 69615 Accepted Submission(s): 12678
Problem Description
Total Submission(s) : 29 Accepted Submission(s) : 15
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
{
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);
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
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);
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
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK
Author
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){
}
2010水仙花数
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 144 Accepted Submission(s) : 27
Font: Times New Roman | Verdana | Georgia
getchar();
while(t--){
int a[1001] = {0}, b[1001] = {0}, c[1001] = {0};
scanf("%s", str1);
len_str1 = strlen(str1);
for(i = 0; i <= len_str1 - 1; ++i)
a[i] = str1[len_str1 - 1 - i] - '0';
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);
Sample Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
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.
if(n < 0 || n >100)
printf("Score is error!\n");
else{
k = n / 10;
switch(k){
case 10: printf("A\n"); break;
case 9: printf("A\n"); break;
case 8: printf("B\n"); break;
}
return 0;
}
成绩转换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25250 Accepted Submission(s): 10776
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))
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");
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)
Sample Output
no
370 371
Author
lcy
Source
C语言程序设计练习(二)
#include <stdio.h>
int main()
{
int m, n, k1, k2, k3, count;
while(scanf("%d %d", &m, &n) != EOF)
{
for(count = 0; m <= n; ++m)
4 28
20 152
Author
lcy
Source
C语言程序设计练习(一)
Statistic|
#include <stdio.h>
int main()
{
int x , y, temp, sum1, sum2;
while(scanf("%d %d", &x, &y) != EOF)
{
sum1 = 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.
Font Size: ← →
Problem Description
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
Total Submission(s) : 65 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
Problem Description
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
Input
输入数据有多组,每组占一行,由一个整数组成。
Output
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
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;
case 7: printf("C\n"); break;
case 6: printf("D\n"); break;
default: printf("E\n"); break;
}
}
}
return 0;
}
2007平方和与立方和
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Output
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120
300 380
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 69615 Accepted Submission(s): 12678
Problem Description
Total Submission(s) : 29 Accepted Submission(s) : 15
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
{
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);
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