Created
April 25, 2014 16:58
-
-
Save mob5566/11296248 to your computer and use it in GitHub Desktop.
A. Squats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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