1804_ykm's blog

By 1804_ykm, history, 17 months ago, In English

The first Test point WA, help!!!

Attached question address:1367A

#include<bits/stdc++.h>
using namespace std;
int n,flag;
string s;
int main(){
	cin>>n;
	while(n--){
		cin>>s;
		for(int i=0;i<s.size();i++){
			if(s[i]!=s[i-1]&&flag>0){
				cout<<s[i];
				flag=0;
			}
			else{
				flag++;
			}	
		}
		cout<<endl;
	}
	return 0;
}

  • Vote: I like it
  • -10
  • Vote: I do not like it

| Write comment?
»
17 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Your code is leaving out the first letter of the answer. You should fix it by putting cout << s[0] before the for loop.