题解 | 编排字符串

编排字符串

https://www.nowcoder.com/practice/42c0673f04b34f66ae236a1cb7995532

#include <iostream>
#include<vector>
using namespace std;

int main() {
    int m;
    string s;
    while (cin >> m) { // 注意 while 处理多个 case
        vector<string>vec;
        for(int i=0;i<m;i++){
            cin>>s;
            if(vec.size()<4){
                vec.push_back(s);
            }
            else {
              
                vec.erase(vec.begin());
                vec.push_back(s);

            }
            for(int j=1;j<=vec.size();j++){
                printf("%d=%s",j,vec[vec.size()-j].c_str());
                if(j!=vec.size())printf(" ");
            }
            printf("\n");
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

learYuan:🐕看了都摇头
点赞 评论 收藏
分享
大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务