poj 1068
作者:互联网
1、注意理解题意
2、注意输出格式
代码:
#include <cstdio>
#include<iostream>
#include<vector>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int num;
cin >> num;
vector<int> vec;
while (num--) {
int c; cin >> c;
vec.push_back(c);
}
vector<int> vecstring;
int temp = 0;
for (int i = 0; i < vec.size(); i++) {
for(int j=0;j<vec[i]-temp;j++)
vecstring.push_back(-1);
vecstring.push_back(1);
temp = vec[i];
}
vector<int> ans;
int count = 0;
for (int i = 0; i < vecstring.size(); i++) {
if (vecstring[i] == 1) {
count++;
for (int j = i - 1;; j--) {
if (vecstring[j] == -1) {
vecstring[j] = 0;
break;
}
if(vecstring[j]==1){
count++;
}
}
ans.push_back(count);
count = 0;
}
}
for(int i=0;i <ans.size()-1;i++)
cout << ans[i]<<" ";
cout << ans[ans.size() - 1];
cout << endl;
}
return 0;
}
标签:count,1068,int,back,++,poj,vec,vecstring 来源: https://www.cnblogs.com/boomclap666/p/15969465.html