编译错误:您提交的代码无法完成编译
第22行:12: error: variable length array of non-POD element type 'string' (aka 'basic_string')
string a[n];
^
第87行:19: warning: comparison of integers of different signs: 'long' and 'size_type' (aka 'unsigned long') [-Wsign-compare]
for (long i = 0;i<vec1.size();i++){
~^~~~~~~~~~~~
第98行:19: warning: comparison of integers of different signs: 'long' and 'size_type' (aka 'unsigned long') [-Wsign-compare]
for (long i = 2;i<a.length();i++){
~^~~~~~~~~~~
2 warnings and 1 error generated.
#include <iostream> #include <vector> #include <string> using namespace std; bool find(vector<string > vec1,string temp,long&index); string yhq(string a); int main(){ long index = 0; long n; long sum = 0; long wenhao; long i; int flag = 0; vector<string> vec1; string temp;bool is; while (cin>>n){ vec1.clear(); wenhao = 0; string a[n]; for (i = 0;i<n;i++){ a[i] = ""; } cin.ignore(); if (n== 0){ cout<<-1<<endl; sum++; continue; } for (i = 0;i<n;i++){ getline(cin,a[i]); } for (i = 0;i<n;i++){ if(a[i][0] == 'I'){ temp = yhq(a[i]); is = find(vec1,temp,index); if (is == true){ if (wenhao>0){ wenhao--; }else { flag = 1; break; } }else { vec1.push_back(temp); } }else if (a[i][0] == 'O'){ temp = yhq(a[i]); is = find(vec1,temp,index); if (is == false){ if (wenhao>0){ wenhao--; }else { flag = 1; break; } }else { vec1.erase(vec1.begin()+index); } }else if (a[i][0] == '?'){ wenhao++; } } if (flag == 0){ cout<<-1<<endl; sum++; } else { cout<<sum<<endl; flag = 0; sum = 0; } } return 0; } bool find(vector<string> vec1,string temp,long&index){ for (long i = 0;i<vec1.size();i++){ if (vec1[i]==temp){ index = i; return true; } } return false; } string yhq(string a){ string temp = ""; for (long i = 2;i<a.length();i++){ temp.push_back(a[i]); } return temp; }
onemoo