插入代码不会自动换行,我也是佛了 #include<bits/stdc++.h> using namespace std; mutex mtx; int active = 0; int n; void print(int thread_idx, int k , char c){ int i = 0; cout << thread_idx << endl; while(i < k) { mtx.lock(); if(active == thread_idx){ cout << c ; active = (active++)%n; i++; } mtx.unlock(); } } int main(){ cin >> n; string s; cin >> s; vector<thread> vth; for(int i = 0; i < s.size(); i++){ vth.push_back(move(thread(print, i, n, s[i]))); } for(auto &t : vth) t.join(); return 0; }
点赞 评论

相关推荐

神哥了不得:放平心态,再找找看吧,主要现在计算机也变卷了,然后就比较看学历了,之前高中毕业你技术强,都能找到工作的
点赞 评论 收藏
分享
牛客网
牛客企业服务