Difference between revisions of "Solução: Problema da fragmentação de memória (Arleson Nunes)"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
Line 11: Line 11:
 
 
 
Fragmentar();
 
Fragmentar();
Girar();
 
 
 
 
}
 
}
Line 50: Line 49:
 
}
 
}
 
 
public static void Girar() {
 
 
string S1 = Console.ReadLine();
 
string S2 = Console.ReadLine();
 
string aux1 = String.Empty;
 
string aux2 = String.Empty;
 
 
if (S1.Length != S2.Length) {
 
Console.WriteLine(0);
 
}
 
else if (S1 == S2) {
 
Console.WriteLine(1);
 
}
 
else {
 
int cont = 0;
 
bool flag = false;
 
while (cont < S1.Length && flag==false) {
 
aux1 = S1.Substring(1, S1.Length - 1);
 
aux2 = S1.Substring(0, 1);
 
S1 = aux1 + aux2;
 
if (S1 == S2) {
 
flag = true;
 
}
 
cont++;
 
}
 
if (flag == true) {
 
Console.WriteLine(1);
 
}
 
else {
 
Console.WriteLine(0);
 
}
 
}
 
 
 
}
 
 
 
 
}
 
}

Revision as of 23:57, 7 April 2009

using System;
 
namespace Fragmentacao
{
	class MainClass
	{
		public static void Main(string[] args)
		{
 
			Fragmentar();
 
		}
 
		public static void Fragmentar() {
 
			int tamanho = int.Parse(Console.ReadLine());
			int[] memoria = new int[int.Parse(Console.ReadLine())];
			int aux = 0;
			int cont = 0;
 
			for (int i = 0; i < memoria.Length; i++) {
 
				aux = int.Parse(Console.ReadLine());
				if (aux <= tamanho) {
					memoria[cont] = aux;
					cont++;
					tamanho = tamanho - aux;
				}
 
			}
 
			int liberacoes = int.Parse(Console.ReadLine());
			int posicao = 0;
 
			for (int j = 0; j < liberacoes; j++) {
 
				posicao = int.Parse(Console.ReadLine());
				if (memoria[posicao] > tamanho) {
					tamanho = memoria[posicao];
				}
				memoria[posicao] = 0;
 
			}
 
			Console.WriteLine(tamanho);
 
		}
 
 
 
	}
}