HDU 2000-2004

继续刷题目,只为锻炼自己代码的熟练程度.今天写了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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值