I don't think so...
Posted: Sat Oct 25, 2003 8:10 pm
I don't think that their are any special cases... What does your alogrithm look like?
Code: Select all
#include <stdio.h>
#include <string.h>
#define MAXNOM 50
#define MAXTOR 200
int getNextToMin(int tam);
void borrarValue(int val, int tam);
void generarArray(int tam);
int getIndex(char name[MAXNOM], int tam);
void procesar(int tam);
void readLine(char *cad);
char tortugas[MAXTOR][MAXNOM];
char tortugasT[MAXTOR][MAXNOM];
int lista[MAXTOR];
int main () {
freopen("P10152.in", "rt", stdin);
int nroTests, nroTor, i , j;
scanf("%d", &nroTests);
while (nroTests!= 0) {
scanf("%d\n", &nroTor);
for (i=nroTor-1; i >= 0; i--){
readLine(&tortugasT[i][0]);
}
for (i=nroTor-1; i >= 0; i--){
readLine(&tortugas[i][0]);
}
nroTests--;
generarArray(nroTor);
procesar(nroTor);
printf("\n");
}
return 0;
}
void readLine(char *cadena){
char c;
int index = 0;
while(( c = getchar() ) != '\n'){
cadena[index++] = c;
}
cadena[index++] = '\0';
}
void generarArray(int tam){
int i;
for(i = 0; i < tam; i++){
lista[i] = getIndex(tortugasT[i], tam);
}
}
int getIndex(char name[MAXNOM], int tam){
int i, res;
for(i = 0; i < tam; i++){
if(strcmp(name, tortugas[i]) == 0){
res = i;
break;
}
}
return res;
}
void procesar(int tam){
int val = getNextToMin(tam), index, i;
index = tam;
val++;
while(val < tam){
lista[index++] = val;
borrarValue(val, tam);
val++;
}
/*mostrar resultado*/
for(i = tam; i < index; i++){
if(lista[i] != (-1)){
printf("%s\n", tortugas[lista[i]]);
}
}
}
void borrarValue(int val, int tam){
int i;
for(i = 0; i < tam; i++){
if(lista[i] == val){
lista[i] = (-1);
break;
}
}
}
int getNextToMin(int tam){
int res = 0, cnt = (-1), i=0, j, bandera;
while(i < tam){
bandera = 1;
for(j = cnt+1; j < tam; j++){
if(lista[j] == i){
bandera = 0;
res = i;
cnt = j;
i++;
break;
}
}
if(bandera) break;
}
return res;
}
Code: Select all
#include <cstdlib>
#include <iostream>
char aOrdenar[200][90];
char Ordenadas[200][90];
char entrada[100];
int tortugos;
int lee_linea( char *s )
{
int ch, n=0;
while( (ch=getchar()) != EOF && ch != '\n' ) {
if ( ch != '\r' ) {
*s++ = ch;
n++;
}
}
*s='\0';
return n;
}
void tortugos_ninja(){
int i=0;
for(int j=0; j < tortugos; j++){
if (strcmp(Ordenadas[i], aOrdenar[j])==0) i++;
}
if(i==tortugos) printf("\n");
else{
if (strcmp(Ordenadas[i], aOrdenar[tortugos-1])==0) i++;
for (;i < tortugos; i++) printf("%s\n",Ordenadas[i]);
}
}
int main(int argc, char *argv[])
{
int casos;
lee_linea(entrada);
casos=atoi(entrada);
while( casos > 0){
tortugos=0;
lee_linea(entrada);
tortugos=atoi(entrada);
for(int i=tortugos-1; i >= 0; i--){
lee_linea(aOrdenar[i]);
}
for(int i=tortugos-1; i >= 0; i--){
lee_linea(Ordenadas[i]);
}
tortugos_ninja();
if(casos > 1) printf("\n");
casos--;
}
}
Code: Select all
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<map>
using namespace std;
struct nd{
nd():a(-1),b(0){}
int a,b;
};
int main()
{
int t;
cin>>t;
while(t--)
{
int dnum;
string fuck;
cin>>dnum;
getline(cin,fuck);
map<string,int> mp;
vector<nd> avec(210);
vector<string>svec(210),vtm(210);
for(int i=0;i<dnum;++i)
getline(cin,vtm[i]);
for(int i=0;i<dnum;++i)
{
getline(cin,svec[i]);
mp[svec[i]]=i;
}
for(int i=0;i<dnum;++i)
{avec[i].a=mp[vtm[i]];
//cout<<"av.a="<<avec[i].a<<endl;
}
int max,mpos;
for(int i=0;i<dnum;++i)
if(avec[i].a == (dnum-1))
{
mpos=i-1;max=dnum-2;avec[i].b=1;break;}
for(int i=mpos;i>=0;--i)
if(avec[i].a==max){avec[i].b=1;--max;}
max=-1;
for(int i=0;i<dnum;++i)
if(!avec[i].b&&avec[i].a>max)max=avec[i].a;
for(int i=max;i>=0;--i)
cout<<svec[i]<<endl;
if(t)cout<<endl;
}
system("pause");
}
Code: Select all
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
int main ()
{
int testCase;
cin >> testCase; // Input the number of test cases
vector <string> output; // This vector stores the output
while ( testCase-- ) {
output.push_back (" ");
int turtle; // variable to hold the number of turtles (names/strings)
cin >> turtle; // Input the number of turtles
getchar(); // Read the next charactor to end the line (to get rid of reading the end of line character)
string input;
vector <string> initial; // This vector will be use to keep turtle names in the initial list
vector <string> final; // This vector will be use to keep turtle names in the final list
for ( int i = 0; i < turtle; i++ ) {
getline(cin, input); // Read the i-th turtle name from the initial list
initial.push_back (input); // Keep the turtle i-th name in the vector
}
for ( int i = 0; i < turtle; i++ ) {
getline(cin, input); // Read the i-th turtle name from the final list
final.push_back (input); // Keep the turtle i-th name in the vector
}
/**********************************
* Main part: You have to implement your solution here
* Your solution should be stored in the vector output.
**********************************/
int m = 0;
int n = 0;
int i = turtle - 1;
while (m>=n&&i>0) {
int m = 0;
int n = 0;
while ( initial[m] != final[i]) {
m++;
}
while ( initial[n] != final[i-1]) {
n++;
}
if (m>=n)
i--;
else
break;
}
if (i == 0)
break;
else {
for (int j = 0;j<=i-1;j++)
output.push_back (final[i-1-j]);
}
}
/**********************************
* End of main part
**********************************/
/**********************************
* Output
**********************************/
for ( unsigned int i = 0; i < output.size (); i++ )
cout << output[i] << endl;
cout << endl;
return 0;
}