90分,第三测试点过不了了,求助感谢感谢!
查看原帖
90分,第三测试点过不了了,求助感谢感谢!
124966
一世我染楼主2023/8/27 10:32
#include<iostream>
//#include<windows.h>
#include<string>
#include<cstdio>
using namespace std;
int main(){
    int ci=0;
    bool flag=0,f2=1;//flag的1表示输出了符号,0没输出。f2的1表示前面有数,0表示是单个的0或1。
    string chuan;
    scanf("%d ",&ci);//空格读取个回车
    getline(cin,chuan);

    for(int i=0;i<=chuan.length();i++){
        if(chuan[i]=='-'){//首位负号
            cout<<'-';
            flag=1;   
            continue;
        }
        else if((chuan[i]=='0'||chuan[i]=='1')&&\
           ((i==0||chuan[i-1]==' '||chuan[i-1]=='-')&&(chuan[i+1]==' '||chuan[i+1]=='\0'))){
            f2=0;
            if((chuan[i]=='1')&&(chuan[i+1]==' '||chuan[i+1]=='\0')&&(i!=0&&chuan[i-1]==' ')){
                if(ci==0)
                    cout<<'+'<<'1';
                else 
                    cout<<'+';
            }
        
            continue;
        }//判断各种特殊情况0,1,-1,-50;     中途-1的情况
        else if((chuan[i]>='0'&&chuan[i]<='9')){
            if(i==0){
                cout<<chuan[i];
                flag=1;
                f2=1;
                continue;
            }
            else if(i!=0&&flag==0){

                    cout<<'+';
                flag=1;
                f2=1;
            }
            if(f2!=0)
                cout<<chuan[i];
            continue;
        }
       
        else if(chuan[i]==' '){
            if(chuan[i-1]=='0'&&f2==0)
                ci--;
            else if(ci==-1)
                ;
            else if(ci==1)//如果一次项
                printf("x",ci--);
            else
                printf("x^%d",ci--);
            flag=0;
            f2=1;
            continue;
        }
    }

    //system("pause");
    return 0;
}//9:53
/*
5 
100 -1 1 -3 0 10
*/

第三测试点数据 3 1 -100 0 0 输出结果: x^3-100x^2 一样啊,为啥过不了呢?因为给的数据最后一位带回车吗?

2023/8/27 10:32
加载中...