الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

احد اسئلة القبول للماجستير في إحدى الجامعات الامريكية

بدأه memento في 21 أغسطس 2009 · 5 رد · 1,348 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Define the fullness quotient of an integer n > 0 to be the number of representations of n in bases 2 through 9 that have no zeroes after the most significant digit , For example, to see why the fullness quotient of 94 is 6 examine the following table which shows the representations of 94 in bases 2 through 9.

base : 2 ,,, representation of 94 :1011110,,,,,, because :: 2^6 + 2^4 + 2^3 + 2^2 + 2^1 = 94

base : 3 ,,, representation of 94 :10111 ,,,,,, because :: 3^4 + 3^2 + 3^1 + 3^0 = 94

base : 4 ,,, representation of 94 :1132 ,,,,,, because :: 4^3 + 4^2 + 3*4^1 + 2*4^0 = 94

base : 5 ,,, representation of 94 :334 ,,,,,, because :: 3*5^2 + 3*5^1 + 4*4^0 = 94

base : 6 ,,, representation of 94 :234 ,,,,,, because :: 2*6^2 + 3*6^1 + 4*6^0 = 94

base : 7 ,,, representation of 94 :163 ,,,,,, because :: 1*7^2 + 6*7^1 + 3*7^0 = 94

base : 8 ,,, representation of 94 :136 ,,,,,, 1*8^2 + 3*8^1 + 6*8^0 = 94

base : 9 ,,, representation of 94 :114 ,,,,,, because :: 1*9^2 + 1*9^1 + 4*9^0 = 94

Notice that the representations of 94 in base 2 and 3 both have 0s after the most significant digit, but the representations in bases 4,5, 6, 7, 8, 9 do not. Since there are 6 such representations, the fullness quotient of 94 is 6

Write a method named fullnessQuotient that returns the fullness quotient of its argument. If the argument is less than 1 return -1. Its signature is

int fullnessQuotient(int n)

Hint: use modulo and integer arithmetic to convert n to its various representations

Examples:

if n is : 1 ,,, return : 8 ,,,, because : Because all of its representations do not have a 0 after the most significant digit: 2:1,3:1,4:1,5:1,6:1,7:1,8:1,9:1

if n is : 9 ,,, return : 5 ,,,, because : Because 5 of the representations (4, 5, 6, 7, 8) do not have a 0 after the most significant digit: 2:1001,3:100,4:21,5:14,6:13,7:12,8:11,9:10

if n is : 360,,, return: 0 ,,,, because :All its representations have a 0 after the most significant digit: 2:101101000,3:111100,4:11220,5:2420,6:1400,7:1023,8:550,9:440

if n is : -4 ,,, return: -1 ,,,,because : The argument must be > 0

هذه احد اسئلة الماجستير لامتحانات القبول في احدى الجامعات الامريكية وبعد حل السؤال وبعثه قال لي انت مستواك بالبرمجة غير جيد وتحتاج إلى الكثير من الاجتهاد ولكن حسبي الله ونعم الوكيل فيهم

سوف اكتب لكم محاولتي في حل السؤال ولا اعلم هل هو صحيح ام اخاطئ فأرجوا من يقرأ هذا السؤال ان يقوم بشرحة وحله لكي اتأكد من الحل والفهم عندي ولكم جزيل الشكر والامتنان

المحاولة

int Convert(int base, int Input)
{
	int Ret=0;
	int factor = 10;

	if(base < 2 || base > 10)
		return 0;

	Ret = Input % base;


	while((Input /= base) > 0)
	{	
		Ret = (Input % base) * factor + Ret;
		factor *= 10;
	}

	return Ret;
}

int fullnessQuotient(int n)
{
	int bRet=0;
	for(int i= 2; i < 10; i++)

		  printf("Base %d => %d\n", i, Convert(i, n));
	return bRet;
}


int main( )
{

int i;
  i= fullnessQuotient (94);

return 0;
}
#2

السلام عليكم,

لم أطلع على حلك بعد, حاولت حل السؤال و هذا حلي, quick/dirty :)

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

std::string convertToBase(int n, int base)
{
	std::string representation;

	while(n > 0)
	{
		representation += static_cast<char>(n % base) + '0';
		n /= base;
	}

	std::reverse(representation.begin(), representation.end());

	return representation;
}

int fullnessQuotient(int n)
{
	std::vector<std::string> numberRepresentation;
	std::size_t count = 0;

	if(n < 1)
	{
		return -1;
	}

	for(int base = 2; base <= 9; ++base)
	{
		numberRepresentation.push_back(convertToBase(n, base));
	}

	for(std::size_t i = 0; i < numberRepresentation.size(); ++i)
	{
		std::string::size_type zero = numberRepresentation.find('0');

		if(zero == std::string::npos)
		{
			count++;
		}
	}

	return count;
}

int main()
{
	int number;

	std::cout << "Enter a number to be examined: ";
	std::cin >> number;

	std::cout << "fullnessQuotient = " << fullnessQuotient(number);
}

تم تعديل هذه المشاركة بواسطة Khaled.Alshaya في 21 أغسطس 2009 في 22:13

#3

هذا حل آخر بعد خمس دقائق أخرى من التفكير.

هذا الحل أفضل برأيي من حلي السابق....

عموماً, رأيت حلك و للأسف أنت لم تجب على السؤال المطروح, كان يجب عليك عد الـ representations التي لا تحتوي على الصفر و من ثم إرجاعها عن طريق الدالة fullnessQuotient :)

#include <iostream>

bool containZero(int number, int base)
{
	while(number > 0)
	{
		if(number % base == 0)
		{
			return true;
		}

		number /= base;
	}

	return false;
}

int fullnessQuotient(int n)
{
	std::size_t count = 0;

	if(n < 1)
	{
		return -1;
	}

	for(int base = 2; base <= 9; ++base)
	{
		count += containZero(n, base) ? 0 : 1;
	}

	return count;
}

int main( )
{
	int number;

	std::cout << "Enter a number to be examined: ";
	std::cin >> number;

	std::cout << "fullnessQuotient = " << fullnessQuotient(number);

	return 0;
}
#4

حل آخر

#include <stdio.h>
#include <conio.h>
int fullnessQuotient(int n)
{
	int count=0;
	int temp;
	if(n<0) return -1;
	for (int base=2;base<=9;base++)
	{
		temp=n;
		while(temp>0)
		{
			if(temp%base==0) {count++;break;}
			temp=temp/base;
		}

	}
	return 8-count;
}
int main()
{
	int num;
	printf("Enter the number : ");
	scanf("%d",&num);
	printf(" the fullnessQuotient of %d is %d\n",num,fullnessQuotient(num));
	getch();
	return 0;
}

سلام

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#5

حل اخر ب #C

class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine(fullnessQuotient(9));
		}

		static int fullnessQuotient(int n)
		{
			if(n < 1)
				return -1;
			int count = 0;

			for (int i = 2; i < 10; i++)
			{
				if (isFullQuotient(n, i))
					count++;
			}

			return count;
		}

		private static bool isFullQuotient(int n, int b)
		{
			int number = n;
			do
			{
				if (number % b == 0)
					return false;
			} while ((number /= b) != 0);
			return true;
		}
	}

تم تعديل هذه المشاركة بواسطة motamayez في 23 أغسطس 2009 في 23:28

مصري في بلاد الفرنجة.

قريباً اقرأ مقالاتي على It-scoop

#6

سؤال خارجي أخ memento بعد إذنك :

شو إسم الجامعة الأمريكية الي قدمتلها ؟؟

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…