Cod sursa(job #664355)

Utilizator andreidanAndrei Dan andreidan Data 19 ianuarie 2012 23:07:50
Problema Litere Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <cstdio>
#include <algorithm>

using namespace std;

char a[10005];
int b[10005];

void swap(char x,char y){
	char aux;
	aux=x;
	x=y;
	y=aux;

}
int main(){
	int n,i,j=0,c;
	
	freopen("litere.in","r",stdin);
	freopen("litere.out","w",stdout);
	
	scanf("%d", &n);
	
	for(i=1;i<=n+1;++i)
		scanf("%c", &a[i]);
	
	for(i=1;i<=n+1;++i)
		b[i]=a[i]-1;
	
	
	
	while(1){
		bool ok=1;
		for(i=1;i<=n;++i)
			if(b[i]>b[i+1]){
				swap(b[i],b[i+1]);
				ok=0;
				++j;
			}
		if(ok) break;
	}
	
	
	/*for(i=1;i<=n+1;++i)
		printf(" %d ", b[i]);*/
	
	printf("%d", j);
	
	
	
	return 0;
}