HDOJ2006:求奇数的乘积

  • 求奇数的乘积

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 37552    Accepted Submission(s): 24220

    Problem Description
    给你n个整数,求他们中所有奇数的乘积。

     

    Input
    输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。

     

    Output
    输出每组数中的所有奇数的乘积,对于测试实例,输出一行。

     

    Sample Input
    3 1 2 3 4 2 3 4 5

     

    Sample Output
    3 15
    #include
    int main()
    {
        int n,t,sum=1,a[1000];
        while(scanf("%d",&n)!=EOF)
        {
            sum=1;
            for(t=0;t
    	

HDOJ2004:成绩转换【多层if语句】

成绩转换

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 61282    Accepted Submission(s): 26616

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!”。

 

Sample Input
56 67 100 123

 

Sample Output
E D A Score is error!

 

Author
lcy

 

Source
解:
#include
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n>100||n=90)
            {
                printf("An");
            }
            else
            {
                if(n>=80)
                {
                    printf("Bn");
                }
                else
                {
                    if(n>=70)
                    {
                        printf("Cn");
                    }
                    else
                    {
                        if(n>=60)
                        {
                            printf("Dn");
                        }
                        else
                        {
                            printf("En");
                        }
                    }
                }
            }
        }
    }
    return 0;
}

没什么好说的,一次过~注意下多重if语句不要写晕掉就好了……

HDOJ2003:求绝对值【不能用fabs()哦】

求绝对值

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 54821    Accepted Submission(s): 27276

Problem Description
求实数的绝对值。

 

Input
输入数据有多组,每组占一行,每行包含一个实数。

 

Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。

 

Sample Input
123 -234.00

 

Sample Output
123.00 234.00

 

Author
lcy

 

Source
C语言程序设计练习(一)
解:
#include 
int main()
{
    double a;
    while(scanf("%lf",&a)!=EOF)
    {
        if(a
fabs()解法
 

HDOJ2002:计算球体积【浮点数除法】

计算球体积

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 67479    Accepted Submission(s): 27011

Problem Description
根据输入的半径值,计算球的体积。

 

Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。

 

Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。

 

Sample Input
1 1.5

 

Sample Output
4.189 14.137
Hint

#define PI 3.1415927

 

Author
lcy

 

Source
C语言程序设计练习(一)
解:
#include
#define PI 3.1415927
 void main()
{
    double r,v;
    while(scanf("%lf",&r)!=EOF)
    {
    r=r*r*r;
    v=(float)4/(float)3;
    v=v*r*PI;
    printf("%.3fn",v);
    }
 }

注意浮点型除法的运算方法:(float)a/(float)b。否则的话是不能计算小数部分的。还有就是关于while语句和!=EOF的用法,很多次错在这个上面了……

HDOJ2000:ASCII码排序

ASCII码排序

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 70659    Accepted Submission(s): 29183

Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

 

Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。

 

Output
对于每组输入数据,输出一行,字符中间用一个空格分开。

 

Sample Input
qwe asd zxc

 

Sample Output
e q w a d s c x z

 

Author
lcy

 

Source
C语言程序设计练习(一)
解:
#include 
 int main()
 {
 char a,b,c,d,x,y,z;
       while(scanf("%c%c%c%c",&a,&b,&c,&d) != EOF)
       {
         x=ab?a:b;
         z=z>c?z:c;
         y=a+b+c-x-z;
         printf("%c %c %cn",x,y,z);
       }
 }

这是我一开始想出来的代码,感觉非常的冗长。要在打代码之前提前打草。好在这道题对长度没有限制……还有就是要看清楚到底是从小到大还是从大到小排列。注意别写错了。

下面放上一个优化的代码:
#include
main()
{
 char a,b,c,d;
 while(scanf("%c %c %c",&a,&b,&c)!=EOF)
 {
     getchar();
  if(a>=b)
  {
   if(c>=a)
   printf("%c %c %cn",b,a,c);
   else if(b>=c)
   printf("%c %c %cn",c,b,a);
   else if(b=b)
   printf("%c %c %cn",a,b,c);
   else if(c>=a)
   printf("%c %c %cn",a,c,b);
   else if(a>c)
   printf("%c %c %cn",c,a,b);
  }
 }
}

【HDOJ】ACM steps 题解目录

整理了一下当时做ACM steps的题解。

写几个关键字让爬虫过来:HDOJ ACM steps 题解 解答 答案

放在这里做成目录:

【ACM】ACM steps 1.1.8

桃花潭水深千尺,不及AC送我情~
A+B for Input-Output Practice (VIII)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40850 Accepted Submission(s): 12244

Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Sample Output
10

15

6
解:

#include
void main()
{
int n,i,j,t,sum,a,out[1000],q;
sum=0;
scanf(“%dn”,&n);
for (i=0;i<n;i++)
{
scanf(“%d”,&j);
for (t=0;t<j;t++)
{
scanf(“%d”,&a);
sum=sum+a;
out[i]=sum;
}
sum=0;
}
q=n-1;
for (i=0;i<q;i++)
{
printf(“%dnn”,out[i]);
}
printf(“%dn”,out[q]);
}

唔,写的比较麻烦。一开始试提示有格式错误.检查了一下,发现是最后面多了一行空行,RT。

当时源代码是这样的:
后来没有很好的解决方法,于是就用了一个笨办法:
于是就变成了这样:
但是HDOJ还是提示格式错误,于是突发奇想在最后的输出那里加了一个n。于是就AC了……
格式错误的原因是最后没有换行……
感觉这个代码好乱,又整理了另外的一个写法:
#include
int main()
{
    int a,b,i,j,l[1000],k;
    scanf(“%d”,&i);
    getchar();
    for(j=1;j<=i;j++)
        l[j]=0;
    for(j=1;j<=i;j++)
    {
        scanf(“%d”,&a);
        getchar();
        for(k=1;k<=a;k++)
        {
            scanf(“%d”,&b);
            getchar();
            l[j]+=b;
        }
    }
    for(j=1;j<=i-1;j++)
        printf(“%dnn”,l[j]);
    printf(“%dn”,l[i]);
}

至此,ACM steps1 系列的题目全部AC~撒花~

【ACM】ACM steps 1.1.7

A+B for Input-Output Practice (VII)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19199 Accepted Submission(s): 12214

Problem Description
Your task is to Calculate a + b.

Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

Sample Input
1 5
10 20

Sample Output
6

30
参考题解:

#include
void main()
{
int a,b,sum;
while(scanf(“%d%d”,&a,&b)!=EOF)
{
sum=a+b;
printf(“%dn”,sum);
printf(“n”);
}
}
 很简单的一道题……
但是有更简单的做法
#include
 main()
 {
    int a,b;
   while(scanf(“%d%d”,&a,&b)!=EOF)
   printf(“%dnn”,a+b);
 }

这貌似是这道题最简单的做法了……

【ACM】ACM steps 1.1.6

A+B for Input-Output Practice (VI)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18437 Accepted Submission(s): 12465

Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input
4 1 2 3 4
5 1 2 3 4 5

Sample Output
10
15
参考题解:

#include
int main()
{
int n,i,sum,t;
sum=0;
while(scanf(“%d”,&n)!=EOF)
{
for(i=0;i

这道题纠结了好久……一开始的写法是这样的,但是一直没有找到错误。

#include
int main()
{
int n,i,sum,t;
sum=0;
while(scanf(“%d”,&n)!=EOF);
{
for(i=0;i

但是HDOJ一直提示WA,也没有找到那里有错误。请教了一下学长,找了好久终于发现while语句后面不应该有分号,否则不会有任何输出…………

鲜血的教训啊……

另附一个正确的写法:

#include
void main()
{
int n,a,i,sum;
while(scanf(“%d”,&n)!=EOF)
{
sum=0;
for(i=0;i
	

【ACM】ACM steps 1.1.5*

A+B for Input-Output Practice (V)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18072 Accepted Submission(s): 13110

Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input
2
4 1 2 3 4
5 1 2 3 4 5

Sample Output
10
15

Author
lcy

参考题解:

#include
int main()
{
    int n,a,b,i,j,sum;
    sum=0;
    while(scanf("%dn",&n)!=EOF)
    {
        for(i=0;i

唔,九点了。感觉有点不在状态。本来打算今天刷完第一系列的,现在看看能刷到多少吧……
这道题也不是很难,尤其是有前一题做铺垫,注意有时候该写注释的写注释,定义的变量太多的话自己会晕掉的= =  。还有就是要注意最后还要对sum进行初始化。