#3809: 求救!!!一直RE但不知道錯在那?


Templar (甜不辣)

學校 : 國立臺中第一高級中學
編號 : 11753
來源 : [60.250.238.157]
最後登入時間 :
2010-07-05 16:05:26
d468. 简单求幂题(求幂系列题3) -- scientific | From: [220.130.233.177] | 發表日期 : 2010-06-01 15:32

#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;

typedef unsigned long long int uint64;

uint64 POW(unsigned int a,unsigned int n)
{
if (n==1) return a;
uint64 temp = POW(a,n/2);
temp *= temp;
if (n&0x01) temp *= a;
return temp;
}

int main(void)
{
enum SIGN{Negtive = -1 , Positive = 1};
SIGN sign;
unsigned int a,n;
char str[1000];
while(gets(str))
{
int strEnd = (int)strlen(str);
int i=0;
a=0;
sign = Positive;
for (i=0;i<strEnd;i++) {
if (str[i]>='0' && str[i]<='9') a = a*10 + str[i] - '0';
else if (str[i]=='-') sign = Negtive;
else break;
}
if ((a==1)&&(sign==Positive)) {
cout << "1\n";
continue;
}
else if ((a==1)&&(sign==Negtive)) {
char buf;
for (;i<strEnd;i++) {
if (str[i]>='0' && str[i]<='9') buf = str[i];
}
cout << ( (buf-'0')&0x01 ? "-1\n" : "1\n");
continue;
}
else if (a==0) {
for (;i<strEnd;i++) if (str[i]>='0' && str[i]<='9') n += str[i] - '0';
if (n==0) cout << "All Over.\n";
else {
cout << "0\n";
return 0;
}
continue;
}
else {
n=0;
for (;i<strEnd;i++) {
if (str[i]>='0' && str[i]<='9') {
n = n*10 + (str[i] - '0');
}
}
uint64 ans = POW(a,n);
if (sign==Negtive) cout << "-";
cout << ans << endl;
}
}
return 0;
}
 
#3810: Re:求救!!!一直RE但不知道錯在那?


Templar (甜不辣)

學校 : 國立臺中第一高級中學
編號 : 11753
來源 : [60.250.238.157]
最後登入時間 :
2010-07-05 16:05:26
d468. 简单求幂题(求幂系列题3) -- scientific | From: [220.130.233.177] | 發表日期 : 2010-06-01 16:29

#include
#include
#include
using namespace std;

typedef unsigned long long int uint64;

uint64 POW(unsigned int a,unsigned int n)
{
if (n==1) return a;
uint64 temp = POW(a,n/2);
temp *= temp;
if (n&0x01) temp *= a;
return temp;
}

int main(void)
{
enum SIGN{Negtive = -1 , Positive = 1};
SIGN sign;
unsigned int a,n;
char str[1000];
while(gets(str))
{
int strEnd = (int)strlen(str);
int i=0;
a=0;
sign = Positive;
for (i=0;i
if (str[i]>='0' && str[i]<='9') a = a*10 + str[i] - '0';
else if (str[i]=='-') sign = Negtive;
else break;
}
if ((a==1)&&(sign==Positive)) {
cout << "1\n";
continue;
}
else if ((a==1)&&(sign==Negtive)) {
char buf;
for (;i
if (str[i]>='0' && str[i]<='9') buf = str[i];
}
cout << ( (buf-'0')&0x01 ? "-1\n" : "1\n");
continue;
}
else if (a==0) {
for (;i='0' && str[i]<='9') n += str[i] - '0';
if (n==0) cout << "All Over.\n";
else {
cout << "0\n";
return 0;
}
continue;
}
else {
n=0;
for (;i
if (str[i]>='0' && str[i]<='9') {
n = n*10 + (str[i] - '0');
}
}
uint64 ans = POW(a,n);
if (sign==Negtive) cout << "-";
cout << ans << endl;
}
}
return 0;
}
與正確輸出不相符(line:59394)
您的答案為: -2 26
正確答案為: 67108864
 
與正確輸出不相符(line:59399)
您的答案為: -7 12
正確答案為: 13841287201
 
您的答案為: -9 18
正確答案為: 150094635296999121
 
怎麼會這樣?? 
 
ZeroJudge Forum