Pagini recente » Borderou de evaluare (job #509312) | Cod sursa (job #559337) | Borderou de evaluare (job #1794930) | Borderou de evaluare (job #2985761) | Cod sursa (job #3350593)
#include <fstream>
using namespace std;
ifstream fin ("litere.in");
ofstream fout ("litere.out");
int main(){
int n, v[10001], t = 0, sol = 0, temp;
char x;
bool test = false;
fin >> n;
for(int i = 1; i<=n; i++){
fin >> x;
if(x=='a'){
v[++t] = 1;
}
else if(x=='b'){
v[++t] = 2;
}
else if(x=='c'){
v[++t] = 3;
}
else if(x=='d'){
v[++t] = 4;
}
else if(x=='e'){
v[++t] = 5;
}
else if(x=='f'){
v[++t] = 6;
}
else if(x=='g'){
v[++t] = 7;
}
else if(x=='h'){
v[++t] = 8;
}
else if(x=='i'){
v[++t] = 9;
}
else if(x=='j'){
v[++t] = 10;
}
else if(x=='k'){
v[++t] = 11;
}
else if(x=='l'){
v[++t] = 12;
}
else if(x=='m'){
v[++t] = 13;
}
else if(x=='n'){
v[++t] = 14;
}
else if(x=='o'){
v[++t] = 15;
}
else if(x=='p'){
v[++t] = 16;
}
else if(x=='q'){
v[++t] = 17;
}
else if(x=='r'){
v[++t] = 18;
}
else if(x=='s'){
v[++t] = 19;
}
else if(x=='t'){
v[++t] = 20;
}
else if(x=='u'){
v[++t] = 21;
}
else if(x=='v'){
v[++t] = 22;
}
else if(x=='w'){
v[++t] = 23;
}
else if(x=='x'){
v[++t] = 24;
}
else if(x=='y'){
v[++t] = 25;
}
else if(x=='z'){
v[++t] = 26;
}
}
while(test!=true){
test = true;
for(int i = 1; i<n; i++){
if(v[i]>v[i+1]){
temp = v[i], v[i] = v[i+1], v[i+1] = temp, sol++, test = false;
}
}
}
fout << sol;
return 0;
}