今天刷了四道题目,虽然同样都是解简单题目,但是慢慢还是会感觉自己解题的速度有所提升。很期待能去解一些难的题目,但还是循序渐进吧,一步一个脚印。以下是解题步骤
HDU 2006
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2006
* 给你n个整数,求他们中所有奇数的乘积。
* Date : 2015/4/22
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
int n,a;
int y = 1;
while(scanf("%d", &n) != EOF){
for(int i = 0; i < n; ++i){
scanf("%d", &a);
if( a % 2 != 0){
y *= a;
}
}
printf("%d\n", y);
y = 1;
}
system("Pause");
return 0;
}
HDU 2007
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2007
* 给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
* Date : 2015/4/22
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
int x,y,temp;
int sum=0,sum2=0;
while(scanf("%d%d", &x, &y) !=EOF ){
if(x > y){
temp = x;
x = y;
y = temp;
}
for(int i = x; i <= y; ++i ){
if( i%2 == 0 ){
sum += i * i;
}
else{
sum2 += i * i * i;
}
}
printf("%d %d\n",sum,sum2);
sum=0;
sum2=0;
}
system("Pause");
return 0;
}
HDU 2008
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2008
* 统计给定的n个数中,负数、零和正数的个数。
* Date : 2015/4/22
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
int num[3] ={0, 0, 0};
int n;
double a;
while(scanf("%d", &n) != EOF){
for(int i = 0; i < n; ++i ){
scanf("%lf", &a);
if(a < 0.0){
++num[0];
}
if( a == 0.0){
++num[1];
}
if( a >0.0){
++num[2];
}
}
if( n !=0 && n< 100 ){
printf("%d %d %d\n", num[0], num[1], num[2]);
num[0] = num[1] = num[2] = 0;
}
}
system("Pause");
return 0;
}
HDU 2009
/* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
* http://acm.hdu.edu.cn/showproblem.php?pid=2009
* 求数列的和
* Date : 2015/4/22
----------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
double n,m;
double sum = 0;
while(scanf("%lf%lf", &n, &m) != EOF && n <10000 & m<1000){
sum += n;
for( int i =0; i < m-1; ++i){
n = sqrt(n);
sum += n;
}
printf("%.2lf\n", sum);
sum = 0;
}
system("Pause");
return 0;
}