注册 登录
编程论坛 C++教室

这个strlen函数有问题吗?

有味 发布于 2010-06-02 14:53, 4758 次点击
程序代码:
#include<iostream>
#include<string>
using namespace std;

const int size=1000010;
char a[size];
int b[size],c[size];
int main ()
{
    int len;
    __int64 count=1;
    while (cin>>a)
    {
          len=strlen(a);
          int j=0;
          for (int i=len-1;i>=0;i--)
              b[j++]=a[i]-'0';
          c[0]=b[0];
          b[len]=1;
          for (int i=1;i<len;i++)
          {
              if (b[i]<c[i-1])
              {
                  b[i]=b[i]+10;
                  b[i+1]=b[i+1]-1;              
              }
              c[i]=b[i]-c[i-1];  
          }   
    if (c[len-1]==0)
    printf("%lld. IMPOSSIBLE\n",count++);
    else
    {
        printf("%lld. ",count++);
        for (int i=len-1;i>=0;i--)
            printf("%d",c[i]);
        printf("\n");
    }
    }
    return 0;   
}
但在poj上交去总是wa,找不出原因。困惑!!!
6 回复
#2
思忆季节2010-06-03 22:50
#include<iostream>
#include<string>
using namespace std;

const int size=1000010;
char a[size];
int b[size],c[size];
int main ()
{
    int len;
    __int64 count=1;
    while (cin>>a)
    {
          len=strlen(a);
          int j=0;
          for (int i=len-1;i>=0;i--)
              b[j++]=a[i]-'0';
          c[0]=b[0];
          b[len]=1;
          for (/*int*/ i=1;i<len;i++)
          {
              if (b[i]<c[i-1])
              {
                  b[i]=b[i]+10;
                  b[i+1]=b[i+1]-1;              
              }
              c[i]=b[i]-c[i-1];  
          }   
    if (c[len-1]==0)
    printf("%lld. IMPOSSIBLE\n",count++);
    else
    {
        printf("%lld. ",count++);
        for (/*int*/ i=len-1;i>=0;i--)
            printf("%d",c[i]);
        printf("\n");
    }
    }
    return 0;   
}
应该是这样吧,那个错误是说你重复定义的意思啦
#3
blueboy820062010-06-03 23:12
poj 上先看看编译器版本和规范啊,一般都是GCC和G++。
#4
gaoce2272010-06-05 09:21
变量重复定义了

[ 本帖最后由 gaoce227 于 2010-6-5 11:13 编辑 ]
#5
有味2010-06-07 22:02
回复 2楼 思忆季节
不是意思我弄错了,应该是Compile Error
他的提示是:
Main.cc: In function 'int main()':
Main.cc:14: error: 'strlen' was not declared in this scope
Main.cc:30: error: 'printf' was not declared in this scope
Main.cc:33: error: 'printf' was not declared in this scope
按你那样改过来还是不对

#6
有味2010-06-07 22:03
用的是G++的编译器
#7
lijm19892010-06-08 11:12
string库 和 cstring库 很不同。。。
而且,C++和C混编也不好玩。。。
只是编译错误而已,根据提示改下就好。。
1