英雄会,二星简单题!小弟我做出来了!系统不承认?
英雄会,二星简单题!我做出来了!系统不承认??
题目:第五届在线编程大赛月赛第一题:完全平方数的个数
题目详情:
给定整数区间[A,B]问其中有多少个完全平方数。
输入格式:
多组数据,包含两个正整数A,B 1<=A<=B<=2000000000。
输出格式:
每组数据输出一行包含一个整数,表示闭区间[A,B]中包含的完全平方数的个数。
答题说明:
输入样例
1 1
1 2
3 10
3 3
输出样例:
1
1
2
0
我的答案:
------解决方案--------------------
int main()
{
……
……
return 1; #异常退出?
}
------解决方案--------------------
其他的不说 就看见你一堆new 都没delete
------解决方案--------------------
sqrt 存在误差 用在这里大概不是一个好主意
------解决方案--------------------
这个算法是错的。
如果输入9,25 输出是3{5-3+1}{3,4,5}对
如果输入10,25 输出也是3{5-3+1}但是只有{4,5}错
楼主最起码也要多验证一下再提交吧!
------解决方案--------------------
别的不说,你内存泄露都漏到天上了.
别认为系统有错了,自己先查查自己吧
题目:第五届在线编程大赛月赛第一题:完全平方数的个数
题目详情:
给定整数区间[A,B]问其中有多少个完全平方数。
输入格式:
多组数据,包含两个正整数A,B 1<=A<=B<=2000000000。
输出格式:
每组数据输出一行包含一个整数,表示闭区间[A,B]中包含的完全平方数的个数。
答题说明:
输入样例
1 1
1 2
3 10
3 3
输出样例:
1
1
2
0
我的答案:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <map>
using namespace std;
typedef map<int, int> mapCin;
map<int, int>::iterator it_cin;
mapCin map_cin;
int testmath(int a, int b)
{
int num = sqrt(long double(a));
num = sqrt(b)-num;
return num+1;
}
void testcin()
{
int a,b;
string line;
const char *cline = new char[30];
char temp[30] = {0};
getline(cin, line);
while(1)//输入
{
cline = new char[30];
cline = line.c_str();
// cout << cline << endl;
strcpy(temp, cline);
if (0 == temp[0])
{
break;
}
sscanf(cline, "%d %d", &a, &b);
// cout << "a=" << a << "b=" << b << endl;
map_cin.insert(make_pair(a, b));
getline(cin, line); //接收下一行
}
}
int main()
{
testcin();
int as = 0;
for(it_cin = map_cin.begin(); it_cin != map_cin.end(); it_cin++)
{
as = testmath(it_cin->first, it_cin->second);
cout << as << endl;
}
return 1;
}
------解决方案--------------------
int main()
{
……
……
return 1; #异常退出?
}
------解决方案--------------------
其他的不说 就看见你一堆new 都没delete
------解决方案--------------------
sqrt 存在误差 用在这里大概不是一个好主意
------解决方案--------------------
int testmath(int a, int b)
{
int num = sqrt(long double(a));
num = sqrt(long double(b))-num;
return num+1;
}
这个算法是错的。
如果输入9,25 输出是3{5-3+1}{3,4,5}对
如果输入10,25 输出也是3{5-3+1}但是只有{4,5}错
楼主最起码也要多验证一下再提交吧!
------解决方案--------------------
别的不说,你内存泄露都漏到天上了.
别认为系统有错了,自己先查查自己吧