题解 | #编排字符串#

编排字符串

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

#include <iostream>
#include <cstdio>
#include <string>
#include <stack>
using namespace std;


int main() {
    int n;
    scanf("%d",&n);
    stack <string> myStack;
    stack <string> temp;
    while (n--) { // 注意 while 处理多个 case
       string s;
       cin>>s;
       myStack.push(s);
       for(int i=1;i<=4 && !myStack.empty();i++){
        printf("%d=",i);
        cout<<myStack.top()<<" ";
        temp.push(myStack.top());
        myStack.pop();
       }
       cout<<endl;
       while(!temp.empty()){
        myStack.push(temp.top());
        temp.pop();
       }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务