继续刷题目,只为锻炼自己代码的熟练程度.今天写了5道题目,虽然都是简单的题目,但都是经过自己思考一个字母一个字母敲出来的。后续将继续坚持手打手敲代码。
HDU 2000
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2000
* ASCII码排序
* Date : 2015/4/20
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
char a[4];
char temp;
while(scanf("%c%c%c%c",&a[0],&a[1],&a[2],&a[3]) != EOF)
{
for(int j = 0;j<3;j++ )
{
for(int i=0;i<3-j;i++)
{
if(a[i]>a[i+1])
{
temp = a[i];
a[i] = a[i+1];
a[i+1]= temp;
}
}
}
printf("%c %c %c\n",a[1],a[2],a[3]);
}
system("PAUSE");
return 0;
}
这道题目error了几次,后来发现回车键也会被scanf到,所以定义四个量,分别比较大小,输出后三个变量,这样就可以将回车键排除掉。
HDU 2001
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2001
* 计算两点之间的距离
* Date : 2015/4/20
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
float x1,y1,x2,y2,d;
while(scanf("%f%f%f%f",&x1,&y1,&x2,&y2) !=EOF )
{
d=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
printf("%.2f\n",d);
}
system("PAUSE");
return 0;
}
HDU 2002
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2002
* 根据输入的半径值,计算球的体积
* Date : 2015/4/20
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#define PI 3.1415927
using namespace std;
int main()
{
double r,s;
while( scanf("%lf",&r) != EOF ){
s=4.0*PI*pow(r,3)/3.0;
printf("%.3lf\n",s);
}
system("PAUSE");
return 0;
}
HDU 2003
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2003
* 求实数的绝对值
* Date : 2015/4/20
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
double a,b;
while(scanf("%lf",&a) !=EOF){
b=fabs(a);
printf("%.2lf\n",b);
}
system("PAUSE");
return 0;
}
HDU 2004
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2004
* 输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
* 90~100为A;
* 80~89为B;
* 70~79为C;
* 60~69为D;
* 0~59为E;
* Date : 2015/4/20
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
int a;
while(scanf("%d",&a) !=EOF){
if(a>=90 && a<=100) printf("A\n");
if(a>=80 && a<=89) printf("B\n");
if(a>=70 && a<=79) printf("C\n");
if(a>=60 && a<=69) printf("D\n");
if(a>=0 && a<=59) printf("E\n");
if(a<0 || a>100) printf("Score is error!\n");
}
system("PAUSE");
return 0;
}