ASCII码排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 131121 Accepted Submission(s): 54019
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe asd zxc
Sample Output
e q w a d s c x z
Author
lcy
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
char n[4];
while (cin >> n)
{
if (n[0] > n[1]) swap(n[0], n[1]);
if (n[1] > n[2]) swap(n[1], n[2]);
if (n[0] > n[1]) swap(n[0], n[1]);
cout << n[0] << ' ' << n[1] << ' ' << n[2] << endl;
}
return 0;
}
计算两点间的距离
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 164353 Accepted Submission(s): 58346
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
Sample Input
0 0 0 1 0 1 1 0
Sample Output
1.00 1.41
Author
lcy
#include<stdio.h>
#include<math.h>
int main()
{
double x1,y1,x2,y2;
double len;
while( ~scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2))
{
printf("%.2f\n",sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))));
}
return 0;
}
计算球体积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 124245 Accepted Submission(s): 50758
Problem Description
根据输入的半径值,计算球的体积。
Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
Sample Input
1 1.5
Sample Output
4.189 14.137Hint#define PI 3.1415927
#include<stdio.h>
#define PI 3.1415927
int main()
{
double r;
while(scanf("%lf",&r)!=EOF)
{
printf("%.3f\n",4*PI*r*r*r/3);
}
return 0;
}求绝对值
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104826 Accepted Submission(s): 51789
Problem Description
求实数的绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
Sample Input
123 -234.00
Sample Output
123.00 234.00
Author
lcy
#include<stdio.h>
int main()
{
double n;
while( scanf("%lf",&n)!=EOF)
{
if(n<0)
{
printf("%.2lf\n",0-n);
}
else
{
printf("%.2lf\n",n);
}
}
return 0;
} 成绩转换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 114698 Accepted Submission(s): 50247
Problem Description
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
Input
输入数据有多组,每组占一行,由一个整数组成。
Output
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。
Sample Input
56 67 100 123
Sample Output
E D A Score is error!
Author
lcy
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(90<=n && n<=100)
{
printf("A\n");
}
else if(80<=n)
{
printf("B\n");
}
else if(70<=n)
{
printf("C\n");
}
else if(60<=n)
{
printf("D\n");
}
else if(0<=n)
{
printf("E\n");
}
else if(n<0 || n>100)
{
printf("Score is error!\n");
}
}
return 0;
}第几天?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 118019 Accepted Submission(s): 42871
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20 2006/3/12
Sample Output
20 71
Author
lcy
#include<stdio.h>
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
int yeari,mounthi,dayi;
int i;
int count;
while(scanf("%d/%d/%d",&yeari,&mounthi,&dayi)!=EOF)
{
count=0;
for(i=0;i<mounthi-1;i++)
{
count=count+day[i];
}
count=count+dayi;
if(((yeari%4==0 && yeari%100!=0) || yeari%400==0)&& mounthi>2)
{
printf("%d\n",count+1);
}
else
printf("%d\n",count);
}
return 0;
}

本文集解答了多个基础编程题目,包括ASCII码排序、计算两点间距离、球体积计算等,适用于初学者练习。
1526

被折叠的 条评论
为什么被折叠?



