劳烦各位大神啦~为什么过不了?

P1307 [NOIP2011 普及组] 数字反转

char_DYX @ 2017-05-16 12:29:57

#include<stdio.h>
#include<string.h>
#define MAXN 12
int sol(int i)
{
    int ans=1;
    for(int j=0;j<i;j++)
    ans*=10;
    return ans;
}
int main()
{
    FILE *fin,*fout;
    fin=fopen("reverse.in","rb");
    fin=fopen("reverse.out","wb");
    //fin=stdin;
    //fout=stdout;
    char s[MAXN];
    int n=0,flag=0,len;
    fscanf(fin,"%s",s);
    len=strlen(s);
    if(s[0]=='-')
    {
        flag=1;
        for(int i=0;i<len;i++)
          s[i]=s[i+1];
    }
    len=strlen(s);
    for(int i=0;i<len;i++)
      n+=(s[i]-'0')*sol(i);
    if(flag)fprintf(fout,"-%d\n",n);
    else fprintf(fout,"%d\n",n);
    fclose(fin);
    fclose(fout);
    return 0;
}

by Endless_ @ 2017-05-21 11:18:41

不要被题目迷惑了...

根本用不到文件输入和输出....

按正常的来写就行...


|