Skip to content

Instantly share code, notes, and snippets.

@mob5566
Created April 25, 2014 16:58
Show Gist options
  • Save mob5566/11296248 to your computer and use it in GitHub Desktop.
Save mob5566/11296248 to your computer and use it in GitHub Desktop.
A. Squats
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
char s[250];
int ans, cnt, nd2;
int ABS( int x )
{
return ( x<0 ? -x : x );
}
int main( void )
{
int i;
while( scanf( "%d", &n ) == 1 ) {
scanf( "%s", s );
nd2 = n/2;
cnt = 0;
for( i = 0; i < n; ++i ) if( s[i] == 'x' )
++cnt;
ans = ABS( nd2-cnt );
if( cnt != nd2 ) {
if( cnt > nd2 ) {
for( i = 0; i < n && cnt != nd2; ++i ) if( s[i] == 'x' ) {
s[i] = 'X';
--cnt;
}
} else {
for( i = 0; i < n && cnt != nd2; ++i ) if( s[i] == 'X' ) {
s[i] = 'x';
++cnt;
}
}
}
printf( "%d\n%s\n", ans, s );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment