求大佬看看为什么0分,明明输出是对的

P1320 压缩技术(续集版)

Hong_teacher @ 2020-11-10 10:31:54

#include<iostream>
#include<sstream>
using namespace std;
//int转为string 
string reversal(int x){
    stringstream s1;
    string s2;
    s1 << x;
    s1 >> s2;
    return s2;
}
int main(){
    string s,last;
    int num;
    while(cin>>s){
        last+=s;
        if(cin.get()=='\n'){
            num=last.length();
            break;
        }
    }
    for(int i=0;i<num-1;i++){
        cin>>s;
        last+=s;
    }

    s="";
    s+=reversal(num);
    s+=" ";
    num=0;
    if(last[0]!='0'){
        s+="0 ";
    }
    for(int i=1;i<=last.length();i++){

        if(last[i]==last[i-1]){
            num++;
        }else{

            s+=reversal(num+1);
            s+=" ";
            num=0;
        }
    }
    cout<<s;
    return 0;
} 

by e的e次方 @ 2020-11-14 22:16:30

朋友,是LINUX评测机的缘故,我也是往下翻了好多帖子才意识到的,LINUX评测机器好像不用\n换行,把所有的“=='\n'”都换成“!=0&&!=1”试试?


|