为啥本地ide没问题 做题的时候输出和我本地ide的不一样

// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<iostream>
#include<string>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
unordered_map<string,int>memo1;
unordered_map<string,int>memo2;
unordered_map<string,int>all;
int times=0;
void dfs(string s,int j){
    s.push_back(' ');
    int flag=0;
    for(int i=0;i<s.size();i++){
        if(s[i]==' '){
            times++;
            string t=s.substr(flag,i-flag);
            if(memo1[t]+memo2[t]==0)all[t]=times;
            if(j==0) memo1[t]+=3;
            else memo2[t]+=1;
            flag=i+1;
            
        }
    }
}
int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<<endl;
    int n,m;
    cin>>n>>m;
    vector<string>strs;
    for(int i=0;i<m;i++){
        for(int j=0;j<2;j++){
            cin.sync();
            string s;
            getline(cin,s);
            dfs(s,j);
            
        }
    }
    for(auto i:memo1){
       strs.push_back(i.first);
    }
    sort(strs.begin(),strs.end(),[&](const string&l,const string &r ){
        if(memo1[l]+memo2[l]==memo1[r]+memo2[r]){
            if(memo1[l]==memo1[r]){
                    if(memo2[l]==memo2[r]){
                        return all[l]<all[r];
                    }
                    return memo2[l]>memo2[r];
            }
            else return memo1[l]>memo1[r];
        }
        else return memo1[l]+memo2[l]>memo1[r]+memo2[r];

    });
    for(int i=0;i<n;i++){
        cout<<strs[i]<<" ";
        
    }

    return 0;
}


#华为#
全部评论
牛客编辑器和本地ide的区别 来个人帮帮看下
1 回复 分享
发布于 2022-04-06 22:48
cout<<strs[i]<<" ";多输出一个空格
点赞 回复 分享
发布于 2022-04-08 17:09
找到原因了 牛客上的getline会先读取一个回车符 可能本地ide做了优化 寄
点赞 回复 分享
发布于 2022-04-06 23:33

相关推荐

03-07 13:32
门头沟学院 C++
未来可欺a:读研吧,这简历只适合学历高的,本科大概率只能干开发,你这个简历开发不匹配,算法和深度学习的话学历又不够
点赞 评论 收藏
分享
ResourceUtilization:我嘞个董事长
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客企业服务