domingo, 17 de noviembre de 2013

Lavabit has been closed.

Lavabit has been closed. Its creator wrote a message to its users.
Lavabit was an email account provider that assured privacy to the users.
It seems that the creator of Lavabit was forced to close by an external agent. May be people is not allowed to have privacy.

Lavabit had another name before.

2013 SWERC D

One exercise about Full Metal Alchemist!
#include<iostream>
#include<string>
#include<vector>

using namespace std;

string hall(string);

int main(){
 int nn;
 cin>>nn;
 for(int z=0;z<nn;z++){
  int n;
  cin>>n;
  string s;
  cin>>s;
  
  string t="";
  for (int i=0;i<n;i++){
   t=hall(t);
  }
  
  cout<< ((t.find(s)==string::npos)?"no":"yes")<<endl;
 }
}

string hall(string s){
 if(s=="") return string("L");
 string res="L";
 char toca='R';
 for(int i=0;i<s.size();i++){
  res+=s[i]+string("")+toca;
  toca=(toca=='L'?'R':'L');
 }
 return res;
}

2013 SWERC A

#include<iostream>
#include<iostream>
#include<string>
#include<vector>

using namespace std;
int nr;
string rul[100][3];

class C{
public:
 int i;
 vector<string> s;
 vector<float> f;
 
 bool max(){return i==s.size();}
 string gets(){return s[i];}
 float getf(){return f[i];}
 C():i(0){}
};

string apply(int r, vector<string> c);

int main(){
 cin>>nr;
 for(int i=0; i<nr; i++){
  cin>>rul[i][0];
  cin>>rul[i][1];
  cin>>rul[i][2];
 }
 
 int rep;
 cin>>rep;
 for(int rrr=0; rrr<rep; rrr++){
  int nc;
  cin>>nc;
  C* col= new C[nc];
  string aux;
  float fl;
  for(int i=0; i<nc; i++){
    cin>>aux;
    while(aux != string("END")){
     col[i].s.push_back(aux);
     cin>>fl;
     col[i].f.push_back(fl);
     cin>>aux;
    }
  }
 
  bool end=false;
  string out="GAMEOVER";
  float max=0;
  string mcol="GAMEOVER";
  while(!end){
   vector<string> in;
  
   for(int i=0;i<nc;i++){
    in.push_back(col[i].gets() );
   }
 
   out="GAMEOVER";
   for(int i=0; i<nr; i++){
    string res=apply(i, in);
    if(res!=""){out=res; break;}
   }
  
   float p=1;
   for(int i=0;i<nc;i++) p*=col[i].getf();
  
   if(p>max && out!="GAMEOVER") {max=p; mcol=out;}
  
   col[nc-1].i++;
   for(int i=nc-1; i>=0; i--){
    if(col[i].max()){
     if(i==0){end=true; break;}
     else {col[i].i=0; col[i-1].i++;}
    }
    else break;
   }
  }
  cout<<mcol<<endl;
 }
}

string apply(int r, vector<string> c){
 int cs= c.size();
 if(cs==1) return c[0];
 
 for(int i=0; i<cs; i++)
  for(int j=i+1; j<cs; j++){
   if((rul[r][0]==c[i] && rul[r][1]==c[j]) || (rul[r][0]==c[j] && rul[r][1]==c[i])){
    vector<string> aux=c;
    aux.erase(aux.begin()+j);
    aux.erase(aux.begin()+i);
    aux.push_back(rul[r][2]);
    for(int k=0; k<nr; k++){
     string res=apply(k,aux);
     if(res != "") return res;
    }
   }
  }
 
 return string("");
}