0

So i am suppose to get line of word and then sort it. but somehow it only worked when j is 1 or above, which means testcase 0 does not do anything... can you tell me how to fix it?

#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_set>
using namespace std;


int main() {
    int tcase, j;
    vector<string> ars;
    cin>>tcase;
    for(j=0; j<=tcase; j++){
        ars.clear();
        string t;
        getline(cin,t);
        istringstream iss(t);
        string word;
        while(iss >> word) {
            ars.push_back(word);
        }

        sort(ars.begin(), ars.end());
        auto it = unique(ars.begin(), ars.end());
        ars.erase(it, ars.end());

        for(int i=0; i<ars.size(); i++){
            cout<<ars[i]<<" ";
        }
        cout<<'\n';
    }
    return 0;
}`
Edit: also initializing j to 1 does not work, which means it need 3 times of looping if there is 2 lines of input

0 Answers0