Hi, how are you??
I'm having problems with this problem...
with this code I got WA:
Code: Select all
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
bool funcion (pair <int, string> a, pair <int, string> b){
return a.first<b.first;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("612.in","r",stdin);
//freopen("10042.out","w",stdout);
#endif
int set,i,j,c,f;
vector <pair<int, string> > lista;
string cad;
scanf("%d\n",&set);
while(set--) {
lista.clear();
scanf("%*d %d\n",&f);
while(f--) {
cin>>cad;
for (i=0,c=0;i<cad.length();i++) {
for (j=i+1;j<cad.length();j++) {
if(cad[i]>cad[j])
c++;
}
}
lista.push_back(pair <int,string> (c,cad));
}
sort(lista.begin(),lista.end(),funcion);
for (i=0;i<lista.size();i++){
cout<<lista[i].second<<endl;
//cout<<lista[i].first<<" "<<lista[i].second<<endl;
}
if (set!=0)
printf("\n");
}
return 0;
}
but with this I got AC
Code: Select all
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
bool funcion (pair <int, string> a, pair <int, string> b){
return a.first<b.first;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("612.in","r",stdin);
//freopen("612.out","w",stdout);
#endif
int set,i,j,c,f;
//vector <pair<int, string> > lista;
vector <pair<int, int> >pos;
vector <string> list;
string cad;
scanf("%d\n",&set);
while(set--) {
list.clear();
pos.clear();
scanf("%*d %d\n",&f);
while(f--) {
cin>>cad;
for (i=0,c=0;i<cad.length();i++) {
for (j=i+1;j<cad.length();j++) {
if(cad[i]>cad[j])
c++;
}
}
list.push_back(cad);
pos.push_back(pair <int,int> (c,list.size()-1));
}
sort(pos.begin(),pos.end());
for (i=0;i<list.size();i++){
cout<<list[pos[i].second]<<endl;
//cout<<lista[i].first<<" "<<lista[i].second<<endl;
}
if (set!=0)
printf("\n");
}
return 0;
}
Both codes were made with the same idea, the difference is that in the WA-code I used a vector < pair<int, string> > to almacenate the strings and the number of flips, while in the AC-code I used 2 vectors: one for the strings and the other for the number of flips.
I have tested both codes with the same inputs and both generated the same output...
why de WA-code gives a WA??
thanx
There is no knowledge that is no power.