অনেকের মধ্যেই একটা ভুল ধারনা আছে। অনেকেই মনে করে যে আধুনিক কম্পিউটারে প্যারালেলিজম সম্ভব। এর পক্ষে যুক্তি দেখানো হয় মাল্টি থ্রেডিং নিয়ে। একটা অ্যাপ্লিকেশনে ৫ টা থ্রেড চালু করা হয় যার প্রত্যেকটি থ্রেড ৫ সেকেন্ড করে সময় নেয়। তাহলে সবগুলা থ্রেড কমপ্লিট হতে ৫ * ৫ = ২৫ সেকেন্ড লাগার কথা। নিচের এই লিঙ্কটিতে এরকম ই উদাহরন দিয়ে মাল্টি থ্রেডের মাধ্যমে দেখিয়েছেন যে পাচটি থ্রেড আসলে ৫ সেকেন্ডেই শেষ হচ্ছে। এটাকেই তারা বলেছেন প্যারালাল প্রসেসিং।
https://howtoprogramwithjava.com/java-multithreading/?hc_location=ufi
প্রথমে থ্রেড নিয়েই বলি। ৫ সেকেন্ডের কাজ দিয়ে আধুনিক প্রসেসরের ক্ষমতা পর্যবেক্ষন করতে চাইলে আমার মতে সেটা হবে প্রসেসরের ক্ষমতাকে অপমান করা। প্রসেসর এতই দ্রুত একটা কাজ শেষ করে অন্য কাজ শুরু করে যা আমাদের চোখে ধরা পরার বাইরে। যেকারনে ৫ সেকেন্ড করে লাগে এমন পাচটা থ্রেড চালালে, সবগুলা থ্রেড মোটামুটি ৫ সেকেন্ডেই শেষ হয়ে যাচ্ছে। কিন্তু তারপরও পাচটা থ্রেড কিন্তু একি সাথে চলে না। টাইম শেয়ারিং এর মাধ্যমে প্রত্যেক থ্রেডের পেছনেই প্রসেসর সময় ব্যয় করে অ্যালগরিদম অনুযায়ী। সেক্ষেত্রে যে কারনে কোন থ্রেড আগে শেষ হবে, কোনটা পরে। একি সাথে ৫ টা থ্রেড শেষ হবে না। যেহেতু, ৫ সেকেন্ডের কাজ দিয়ে প্রসেসরের ক্ষমতা বোঝা যাবে না, তাই এই থ্রেড গুলোর সময় বাড়িয়ে একঘন্টা করে দেখা যেতে পারে। মানে একঘন্টা করে সময় লাগে এমন ৫ টা থ্রেড একসাথে শুরু করব এবং এবং কোন থ্রেড কখন শেষ হয় তার সময় টা নোট করব। আগ্রহীরা উপরের উদাহরনের কোডটা একটু মডিফাই করেই এই পরীক্ষা টা করে দেখতে পারেন।
এবার প্রসেস নিয়ে কথা বলি। ধরে নেই, কোর আই X প্রসেসরে ৫ টা কোর (মাইক্রো প্রসেসর) থাকে। আসলে ব্যপারটা এমন যে এই কম্পিউটারের মুল প্রসেসর ৫ টা যারা আসলেই টাস্ক প্রসেস করে। আর আমরা যেটাকে প্রসেসর বলি সেটি আসলে একটা কন্টেইনার যার ভেতর সেই মুল ৫ টা কোর প্রসেসর গুলো থাকে। এই কন্টেইনার প্রসেসরের কাজ হল যখন কোন টাস্ক আসবে তার কাছে তখন সে অ্যালগরিদমের উপর নির্ভর করে ওই সময়ের পটেনশিয়াল কোর প্রসেসরকে টাস্কটা অ্যাসাইন করবে। এখন আপনি ৫ টা প্রসেস (প্রত্যেক প্রসেস কম্প্লিট হতে সময় লাগে ৫ মিনিট)একি সময়ে স্টার্ট করলেন। প্রত্যেক কোর প্রসেসর কে একটা করে টাস্ক অ্যাসাইন করা হল। তাহলে একি সাথে সবগুলো প্রসেস কম্প্লিট হবে ৫ মিনিটেই যেখানে ৫ * ৫ = ২৫ মিনিট লাগার কথা ছিল। হ্যা, আপনার মনে হতে পারে যে এখানে প্যারালাল প্রসেসিং হল।
এটা কি সবসময় ৫ মিনিটেই হবে? ভেবে দেখুন তো। ধরেন আপনার ৫ টা কোরের মধ্যে এই মুহুর্তে ৪ টা ফ্রি আর একটা ব্যাস্ত আছে। তখন এই ৫ টা প্রসেস কম্প্লিট হতে ১০ মিনিটের বেশী সময় লাগবে ( প্রথম ৪ টা টাস্ক শেষ হবে ৫ মিনিটে। তারপর যখন কোন প্রসেসর ফ্রি হবে তখন ৫ নম্বর টাস্ক টা শুরু হবে এবং এটা শেষ হতে আরও ৫ মিনিট সময় লাগবে)। ধরেন, এখন ৪ টা কোর ই ব্যস্ত। আপনার জন্য শুধু একটা কোরই ফ্রি আছে। তখন সময় লাগবে ২৫ মিনিট।
মানুষের ব্রেইন এর নিউরন গুলো হল এক একটা কোর প্রসেসিং ইউনিট। যদিও মানুষের ব্রেইন আসলেই কিভাবে কাজ করে তা এখনো শতভাগ বের করা সম্ভব হয় নি তবে মোটামুটি একটা আইডিয়া করে সেই জিনিসটাই ইম্পলিমেন্ট করেই কম্পিউটারের প্রসেসর বানানোর চেষ্টা করা হচ্ছে।
অনেক সময় আমাদের এমন হয়, হঠাৎ কোন কিছু একটা মনে করতে চাইলাম। কিন্তু কিছুই মনে পড়ছে না (আঞ্চলিক ভাষায়, পেটে আছে, মুখে নাই)। ২-১ দিন পর অন্য কোন কাজ করছেন এমন সময় হঠাৎ করেই সেই জিনিস টা মনে পড়ে গেল। হয় না এমন? এর কারন হচ্ছে কোন একটা নিউরন ওই জিনিসটা খোজার কাজে ব্যস্ত ছিল। যখনি পেয়েছে সাথে সাথে আপনাকে জানিয়ে দিয়েছে। ওই সময়ে ওই নিউরন টা শুধু এই একটা কাজেই ব্যস্ত ছিল। মানুষের ব্রেইন আসলে মাল্টি টাস্কিং করে মাল্টিপল সংখ্যক প্রসেসর (নিউরন) দিয়ে। এখানেও প্যারালেলিজম পাওয়া যায় নি।
ভাষাগত ভুল ত্রুটি ক্ষমাসুন্দর দৃষ্টিতে দেখবেন।
]]>ধাপ ১ঃ প্যারাগ্রাফ এর প্রথম ক্যারেকটার থেকে শুরু করে একটা একটা করে সামনে আগাতে হবে।
ধাপ ২ঃ কোন শব্দের প্রথম অক্ষর যদি ‘N’ হয় তাহলে এই ইনডেক্সে একটি পয়েন্টার রাখতে হবে। এরপর এই ইনডেক্স থেকে আবার সামনে আগাতে হবে। যদি শব্দটির শেষ অক্ষরে পৌছানোর আগে ‘H’ পাওয়া যায় এবং শেষ অক্ষরটি যদি ‘L’ হয় তাহলে এটা একটি কাঙ্খিত শব্দ। এই শব্দটি কে একটি স্ট্রিং টাইপ অ্যারে তে স্টোর করে রাখি।
ধাপ ৩ঃ যদি এমন হয় যে আমরা শব্দটির শেষ অক্ষরে পৌছে গেছি কিন্তু উপরের দেওয়া প্যাটার্ন ম্যাচ করেনি তাহলে আবার ‘N’ দিয়ে শুরু হওয়া নতুন শব্দ না পাওয়া পর্যন্ত সামনে আগাতে হবে। যদি কোন শব্দের প্রথম অক্ষর ‘N’ হয় তাহলে ধাপ ২ এ ফিরতে হবে।
ধাপ ৪ঃ প্যারাগ্রাফটির শেষ অক্ষর ভিজিট হয়ে গেলে প্রোগ্রামটি বন্ধ হয়ে যাবে।
অবশেষে একটি স্ট্রিং টাইপ অ্যারেতে ওই নির্দিষ্ট প্যাটার্নের সকল শব্দ জমা হবে। উপরে অ্যালগোরিদমটির সংক্ষেপ বর্ননা দেওয়া হল। কিন্তু এই অ্যালগরিদমটির ইমপ্লিমেন্টেশন টা করতে গেলে যাযা লাগবে তা নিচে দেওয়া হলঃ
১। কমপক্ষে ৩ টি ভ্যারিয়েবল যা ফ্ল্যাগ হিসেবে ব্যবহার করা হবে বিভিন্ন ইনডেক্স স্টোর করে রাখার জন্য।
২। একটি For লুপ।
৩। অসংখ্য if-else ব্রাঞ্চিং।
৩। একটি ক্যারেকটার টাইপ স্ট্রিং যেটাতে খুজে পাওয়া কাঙ্খিত সকল শব্দ থাকবে।
আচ্ছা ভাবুন তো, এতকিছু না করে যদি এক লাইনে কাজটি সেরে ফেলা যেত তখন কেমন হত? ধরি, মিঃ আরএ নামে একজন মানুষ আছেন যিনি অনেক দ্রুত ও অনেক সহজে কোন প্যারাগ্রাফ থেকে নির্দিষ্ট প্যাটার্নের শব্দগুলো খুঁজে বের করতে পারেন। অর্থাৎ আমরা যদি মিঃ আরএ কে প্যাটার্ন ও প্যারাগ্রাফ বলে দেই তাহলে উনি অতি দ্রুত ওই প্যারাগ্রাফ সম্পুর্নটা থেকে প্যাটার্নটির সাথে মিলে যায় এমন সব শব্দ খুঁজে বের করে দেয়। তাহলে উপরের সেই অ্যালগরিদমের পরিবর্তে যদি একলাইন লিখে মিঃ আরএ কে প্যাটার্ন আর প্যারাগ্রাফ দিয়ে দেই তাহলে অনেক সহজে, অনেক কম কষ্টে, অনেক কম কোড লিখে, অনেক কম সময়ে আমরা আমাদের কাঙ্খিত শব্দের লিস্ট টি পেয়ে যাব।
মিঃ আরএ যদি মানুষ হত তাহলে আমরা তাকে যেভাবে প্যাটার্নটির কথা বলতাম কম্পিউটারকে তো আর সেভাবে বলা যাবে না। তাই আমাদের কে কিছু নির্দিষ্ট নিয়ম মেনে আমরা যে প্যাটার্নের শব্দ চাচ্ছি তার জন্য একটি এক্সপ্রেশন লিখতে হবে। এই যে এক্সপ্রেশনটি আমরা মিঃ আরএ কে দেব সেটাই আসলে রেগুলার এক্সপ্রেশন। এবং মিঃ আরএ কে বলব রেজেক্স ইনজিন। বর্তমানে মোটামুটি সকল প্রোগ্রামিং ল্যাঙ্গুয়েজেই রেজেক্স ইন্জিন ইনটিগ্রেট করা আছে। তাই আমরা নিজ প্রয়োজনমত রেগুলার এক্সপ্রেশন লিখে সার্চ মেথডে প্যারামিটার হিসেবে এক্সপ্রেশন আর প্যারাগ্রাফ অথবা স্ট্রিং টি দিলেই ইনজিন আমাদেরকে কাঙ্খিত প্যাটার্নের সকল শব্দের লিস্ট দিয়ে দেবে।
রেজেক্সওয়ান ডট কম থেকে মাত্র এক থেকে দুই ঘন্টা দেখলেই রেগুলার এক্সপ্রেশন সহজে শেখা যাবে। ছোট ছোট সাইজের লেসন এর সাথেই রয়েছে সরাসরি প্র্যাকটিস করার সুযোগ।
রেজেক্সওয়ানিজরোওয়ান ডট কম একটি অনলাইন টুল যা ব্যবহার করে খুব সহজেই কাঙ্খিত রেগুলার এক্সপ্রেশনটি জেনারেট করা যায়।
উদাহরন ও ব্যবহারিক প্রয়োগঃ
যাদের জুমলা ও ভার্চুমার্ট কমপোনেন্ট সম্পর্কে ধারনা আছে তারা নিশ্চয়ই জানি যে, ভার্চুমার্টে যখন কোন প্রোডাক্ট আপলোড হয় তখন ওই প্রোডাক্টের ইমেজ আপলোড করে এবং রিসাইজ করে একই ইমেজের একটি রিসাইজইড ভারসন তৈরী করে। ডাটাবেজের XX_virtuemart_media নামক টেবিলে file_url এবং file_url_thumb নামক কলামে যথাক্রমে মুল ইমেজ ও রিসাইজড ইমেজের পাথ স্টোর করে রাখে। ২০১২ সালের দিকে আমি জুমলার একটি মডিউল বানিয়েছিলাম যেটা একটা নির্দিষ্ট ক্যাটেগরী থেকে কিছু নির্দিষ্ট বৈশিষ্ট্যের সকল প্রোডাক্টের লিস্ট ডিসপ্লে করে। মডিউল টির নাম mod_votecounter যেটি বর্তমানে মডিউলটি এখানে সাইটে রানিং আছে। লিস্ট এ ডানপাশে যে ইমেজ গুলো দেখছেন সেগুলো রিসাইজড ভার্সন ইমেজ। ইমেজের নাম ও পাথ ডাটাবেজের XX_virtuemart_media টেবিলের file_url_thumb কলাম থেকে img ট্যাগ এর মাধ্যমে দেখানো হয়েছে। কিছুদিন আগে সাইটটির মালিক বা আমার ক্লায়েন্ট জুমলা ও ভার্চুমার্ট এর ভার্সন আপগ্রেড করে। এর পর থেকে ওই লিস্টটিতে ডানদিকে আইটেমের ইমেজ দেখাচ্ছিল না। অ্যানালাইসিস করে যা জানলাম, তার সারমর্ম হল এরকম, প্রোডাক্ট ইমেজ আপলোড করার সময় ভার্চুমার্ট কম্পোনেন্ট টি ওই একি ইমেজের রিসাইজ্ড ইমেজ তৈরী করে একই পাথে resized নামক ফোল্ডার এ নির্দিষ্ট নেমিং কনভেনশন ফলো করে রাখে। এই কারনে ভার্চুমার্ট এর লেটেস্ট ভার্সন গুলোতে file_url_thumb টি ফাঁকা থাকে। যেহেতু file_url কলাম থেকেই ওই ইমেজের এবং সেটার রিসাইজড ভার্সনের পাথ পাওয়া সম্ভব তাই ভার্চুমার্ট এখন আর file_url_thumb এ কোন পাথ রাখে না। যদি রিসাইজড ইমেজ টি কোন কারনে ওভাররাইট করা হয় শুধুমাত্র সেক্ষেত্রে file_url_thumb এ ওভাররাইট করা ইমেজের পাথ স্টোর করে রাখে।
সমস্যাঃ
তাহলে লেটেস্ট ভার্সনে file_url_thumb ফাঁকা। আমাকে file_url থেকেই রিসাইজড ইমেজের পাথ জেনারেট করতে হবে। নিচে মুল ইমেজের পাথ ও রিসাইজড ইমেজের পাথ কেমন হবে তার একটি উদাহরন দেওয়া হলঃ
মুল ইমেজ ঃ /images/stories/virtuemart/product/product_photo.jpg
রিসাইজড ইমেজঃ /images/stories/virtuemart/product/resized/product_photo_200x200.jpg
রিসাইজড ইমেজের বোল্ড করা অংশটুকু দেখেই পার্থক্য বোঝা যাচ্ছে। অর্থাৎ আমাকে এখন এমন একটি রেগুলার এক্সপ্রেশন বানাতে হবে যেটা দিয়ে মুল ইমেজ পাথকে ৩ টা ভাগে ভাগ করা যায়। ভাগ গুলো নিম্নরুপঃ
প্রথম অংশ ঃ /images/stories/virtuemart/product/
দ্বিতীয় অংশঃ product_photo
তৃতীয় অংশঃ .jpg
রেজেক্স ইন্জিন কে যদি এই রেগুলার এক্সপ্রেশন ও মুল ইমেজ পাথ টা দেই তাহলে ইন্জিনটি আমাদের কে উপরের মত করে তিনটা আলাদা স্ট্রিং রিটার্ন করবে। এরপর আমরা নিচের মত করে রিসাইজড ইমেজ পাথ জেনারেট করব।
[string1]resized/[string2]_200*200[string3]
তাহলে এখন আমরা এমন একটি মেথড লিখব যা ইনপুট হিসেবে মুল ইমেজের পাথ নিবে এবং রিসাইজড ইমেজের পাথ রিটার্ন করবে।
/** * @param $media String file_url of product image of virtuemart * @return $thumb_url string automatically generated thumb url */ function generateThumbUrl($media = false){ $thumb_url = preg_replace("/(((w+)/)+)(.+)(.jpg)/i", "$1resized/$4_200x200$5", $media); return $thumb_url; }
এই কোডটিতে “(((w+)/)+)(.+)(.jpg)” করা অংশটুকুই একটি রেগুলার এক্সপ্রেশন যে একটা ইমেজ পাথ কে পুর্বের নিয়ম অনুযায়ী তিনটি গ্রুপে ভাগ করবে। preg_replace একটি PHP মেথড যা তিনটি প্যারামিটার ইনপুট হিসেবে নেয়। প্রথমটি হবে রেগুলার এক্সপ্রেশন, দ্বিতীয়টি নতুন স্ট্রিং টির প্যাটার্ন এবং তৃতীয়টিতে মুল স্ট্রিং যেটা থেকে নতুন স্ট্রিং জেনারেট করতে হবে। উপরের কোডটিতে preg_replace মেথডটি $media এর উপর রেগুলার এক্সপ্রেশন (((w+)/)+)(.+)(.jpg) এক্সিকিউট করে অনেকগুলো নেস্টেড ভাগে ভাগ করে যেখানে $1 এ থাকে মুল ইমেজের প্রথম অংশ, $4 এ থাকে দ্বিতীয় অংশ এবং $5 এ থাকবে শেষ অংশ। তাহলে আমাদের নতুন স্ট্রিংটির প্যাটার্ন হবে $1resized/$4_200x200$5
regex101.com এর টুলটি ব্যবহার করে সরাসরি নির্দিষ্ট প্যাটার্নের জন্য রেগুলার এক্সপ্রেশন জেনারেট করা যায়।
এই পোস্টটিতে শুধুমাত্র রেগুলার এক্সপ্রেশনের সম্পর্কে ধারনা দেওয়া হল। বিস্তারিত জানতে উপরে উল্লিখিত সাইটে যেতে হবে।
]]>As per my knowledge, If we learn these things with practicing some code related to these topics, we can start for any kind of development or to take in part in java related exams.
I am sorry to say that I can’t share these things right now. But in near future, a brief of these topics will be here.
[polldaddy poll=7717806]
]]>An API (application programming interface) is a term meaning the functions/methods in a library that we can call to ask it to do things for us – the interface to the library.
An SDK ( (software development kit) is a library (often with extra tool applications, data files and sample code) that aid us in developing code that uses a particular system (e.g. extension code for using features of an operating system (Windows SDK), drawing 3D graphics via a particular system (DirectX SDK), writing add-ins to extend other applications (Office SDK), or writing code to make a device like an Arduino or a mobile phone do what we want)
[Collected]
HAPPY NEW YEAR, 2014
Code Written in JAVA
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.*; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Ujjal Suttra Dhar */ class create_backup{ String database = "your_database_name", user = "root", password = "pass"; Connection m_Connection = null; Statement m_Statement = null; ResultSet m_ResultSet; String m_Driver = "com.mysql.jdbc.Driver"; String m_Url = "jdbc:mysql://localhost:3306/" + database; public create_backup(){ /*Eshtablishment of Connection of java code with MySQL using JDBC You must read my previous post to know further about this. */ try { Class.forName(m_Driver); m_Connection = DriverManager.getConnection(m_Url, user, password); //Create Statement object m_Statement = m_Connection.createStatement(); } catch (Exception ex) { ex.printStackTrace(); } try { //Database will be stored in filename.sql which can be import on MySQl as backup BufferedWriter out = new BufferedWriter(new FileWriter("kernel_school.sql")); //Now here is the informations about the database of which backup will be created String dump = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump " //Path to mysql + "--host=localhost" //Mysql hostname + "--port=3306" //Mysql portnumber + "--user=root" //Mysql username + "--password=pass" //Mysql password + "--add-drop-table" //Add a DROP TABLE statement before each CREATE TABLE statement + "--add-drop-database" //Add a DROP DATABASE statement before each CREATE DATABASE statement + "--complete-insert" //Use complete INSERT statements that include column names. + "--extended-insert" //Use multiple-row INSERT syntax that include several VALUES lists + "kernel_school"; //Mysql databasename //executing the command through process. Process run = Runtime.getRuntime().exec(dump); /*resultant SQL informations are here on the br which can be read line by line . And at the same time it will be written on another sql file.*/ InputStream in = run.getInputStream(); InputStreamReader isr = new InputStreamReader(in); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine())!=null) { out.write(line); out.newLine(); } out.flush(); // must flush or close the file after completing the task. // int exitVal = run.waitFor();//when exitVal is ,then the process is completed } catch (Throwable t) { t.printStackTrace(); } }//constructor } // class public class autobackup { public static void main(String a[]){ new create_backup(); } }
Code Written in PHP
]]>
Step 1:
Find some books on basic mathematics/Number theory.
* Elementary Number Theory with Applications
-Thomas Koshy
*Concrete mathematics
-Donald Knuth
Step 2:
Select an programming language to implement those mathematics you have learnt. Now-a-days, C,C++,JAVA are the most popular and widely used languages. If you are newbie ,I will suggest you to learn C because it is the most efficient and easiest language. Most of important softwares and Some of operating systems are developed in C.
If you are not a student of CSE background,don’t be afraid,because you can learn it easily. You can learn this from this book. Ya, all the newbies who are related to CSE,this book is also for you too.
*Art Of Programming contest
* Programming with C
-Bayron Gottfried
Step 3:
Now you have learnt a little bit of mathematics, at least one of the programming languages, it’s time go now. What to do? You have to solve problems.There are many Online judges,In which there are thousands of problem descriptions with the facility to judge your solution ,is it ok or not,I will mention “Is the solution efficient or not”.
As you are newbie I will suggest you to use UVA at first . For this you have to open an account on this site.you can browse problems of their site. The first job of you to read the problem carefully,find the solution ,then code it.
What is coding? If you have learnt any of the programming languages, don’t ask it again.You have to write a code which will take input and provide with outputs as the problem description. After login you have to submit your solution to the onlinejudge.That machine will judge your solution in RE (runtime error),TE (time limit exceede),WA (wrong answer),PA (presentation error) and AC (accepted).
When submitting,you have take some measures which will be described below.
You can track your progress from here .
After solving some of problems,you should not be limited only in a single judges.
Here are some others OJs.
*SPOJ
*Light OJ
*Topcoder
*Codeforces
Here are some of websites/blogs which can be useful for you too.
*Smilitude
* UVA FORUM
Problems solving with C:
A sample code for submitting a problem is given below.
[code]
#include<stdio.h>
int main()
{
int testcase,input,I,j,k;
while(scanf(“%d”,&input)==1)
{
//your solution exists here
If(input ==2)
printf(“two”);
else
printf(“Not two”);
}
return 0;
}
[/code]
Now practice problem solving. You must attend free online contests to judge yourself.
For any kind of help or suggestions
I am here
যাই হোক,কাজটা client এর পছন্দও হল। কিন্তু এখন পর্যন্ত উনি আমাকে pay করেন নাই। প্রথম কাজেই ধরা খাইলাম। ব্যাপার না। আরও হবে। আপাতত সেই কাজ তাই আপনাকে দেখাচ্ছি।
updater after 2 days
দেরীতে হলেও ফিডব্যাক পাওয়া গেল।টাকাও।
Here is the input/output format
Input
Input starts with an integer T, denoting the number of test cases.
Each case begins with an integer n denoting the number of nodes. Then there will be n lines, each having n space separated integers, denoting the lengths of two connected nodes. Each length will be between 0 and 100.
Output:
If generating a tree is impossible ,then output is -1 else the minimal cost.Example:
Input:
32
27 26
1 524
0 10 10 0
0 0 1 1
0 0 0 2
0 0 0 04
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0Output:
Case 1: 105
Case 2: 12
Case 3: -1
[code]
import java.util.*;
class edge {
public int dist;
int st, end;
edge(int i, int j, int k) {
this.st = i;
this.end = j;
this.dist = k;
}
};
class exe {
public edge road[] = new edge[3000];
edge ce;
int arr[][] = new int[52][52];
int rank[] = new int[52];
int par[] = new int[52];
double ans = 0;
int min1 = 0, max1 = 0;
int cost;
int C, R, cnt, E;
int find(int i) {
if (i != par[i]) {
par[i] = find(par[par[i]]);
}
return par[i];
}
void link(int x, int y) {
if (rank[x] > rank[y]) {
par[y] = x;
} else {
par[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
void kruskal() {
int i = 0, j = 0, u, v, flag = 0;
System.out.println("Tree diagram is ");
for (i = 0; j < C – 1 && i < E; i++) {
u = find(road[i].st);
v = find(road[i].end);
if (u == v) {
continue;
}
link(u, v);
flag = 1;
j++;
min1 += road[i].dist;
System.out.println(road[i].st + "->" + road[i].end + " cost is " + road[i].dist);
}
if (j < C – 1) {
System.out.println(-1);
} else {
//System.out.println(max1-min1);
System.out.println("Minimal Cost is " + min1);
}
} //krus
public exe() {
int i, j, k, T, cs = 0;
Scanner s = new Scanner(System.in);
T = s.nextInt();
while (true) {
if (T == 0) {
break;
}
C = s.nextInt();
for (i = 1; i <= C; i++) {
par[i] = i;
rank[i] = 0;
}
k = 0;
max1 = 0;
for (i = 1; i <= C; i++) {
for (j = 1; j <= C; j++) {
arr[i][j] = s.nextInt();
if (arr[i][j] != 0 && i != j) {
road[k] = new edge(i, j, arr[i][j]);
k++;
}
max1 += arr[i][j];
}
}
E = k;
for (i = 0; i < E – 1; i++) {
for (j = i + 1; j < E; j++) {
if (road[i].dist > road[j].dist) {
ce = road[i];
road[i] = road[j];
road[j] = ce;
}
}
}
min1 = 0;
System.out.print("Case " + (++cs) + ": ");
kruskal();
T–;
} // while
}
}//class exe
public class Ezdia1 {
public static void main(String ars[]) {
try {
exe object = new exe();
} catch (Exception p) {
}
}
//main
}//class
[/code]
ধন্যবাদ সবাইকে।
]]>[code]
jar cf jar-file input-file(s)
[/code]
//input files are .class files and extra files you have used like music,jars etc.
For more you can see this Creating JAR files
After creation you must specify the main class using manifest.
Ways to update a jar file with manifest……
I have created a text file as manifest like aaa.txt which contains
[Code]Main-class: Mainclassname
[/Code]
//a new line or enter must be pressed after Mainclassname before saving
Updating a jar file with main class, you have to move the jar file to the BIN folder of JDK. Then using the command propmt executed the commands given below:
[code]
jar umf aaa.txt calender.jar
jar xvf calender.jar
type META-INFMANIFEST.MF
[/code]
Now double-click on your JAR file….
Thanking you,
Ujjal
For example:
(a+[b-{c*(d-e)}]+f) is correctly bracketed but (a+[b-{c*(d-e)]}+f) is not correctly bracketed.
Solution:
This is the case if
(a) There are the same number of left and right bracketes of each kinds,and
(b) When a right bracket appears,the most recent preceeding unmatched left bracket should be of the same type.
This can be decided by using stack. The expression is scanned left to right. When a left bracket is encountered,it is pushed onto the stack. When a right bracket is encountered, the stack is poped (if the stack is empty ,there are too many right brackets) and the brackets are compared. If they are of the same type,the scanning continues.If there is a mismatch,the expression is incorrectly bracketed. At the end of the expression ,if the stack is empty ,the expression is correctly bracketed otherwise there are too many left brackets.
[code]
.model small
.stack 100h
.data
cr equ 0DH ; cr represents carriage return
lf equ 0AH ; lf represents line feed
msg DB cr,lf,’ENTER AN ALGEBRIC EXPRESSION : ‘,cr,lf,’$’
msg_correct DB cr,lf,’EXPRESSION IS CORRECT.$’
msg_left_bracket DB cr,lf,’TOO MANY LEFT BRACKETS. BEGIN AGAIN!’,cr,lf,’$’
msg_right_bracket DB cr,lf,’TOO MANY RIGHT BRACKETS. BEGIN AGAIN!’,cr,lf,’$’
msg_mismatch DB cr,lf,’BRACKET MISMATCH. BEGIN AGAIN!’,cr,lf,’$’
msg_continue DB cr,lf,’Type Y if you want to Continue : ‘,cr,lf,’$’
.code
main proc
mov ax,@data ;get data segment
mov ds,ax ;initialising
start:
lea dx,msg ;user prompt
mov ah,9
int 21h
xor cx,cx ;initializing cx
mov ah,1
input: ;this label for taking input
int 21h
cmp al,0Dh ;checking if the enter is pressed or not
JE end_input
;if left bracket,then push on stack
cmp al, "["
JE push_data
cmp al, "{"
JE push_data
cmp al, "("
JE push_data
;if right bracket,then pop stack
cmp al, ")"
JE parentheses
cmp al, "}"
JE curly_braces
cmp al, "]"
JE line_bracket
jmp input
push_data:
push ax
inc cx
jmp input
parentheses:
dec cx
cmp cx,0
JL many_right
pop dx
cmp dl, "("
JNE mismatch
JMP input
curly_braces:
dec cx
cmp cx,0
JL many_right
pop dx
cmp dl, "{"
JNE mismatch
JMP input
line_bracket:
dec cx
cmp cx, 0
JL many_right
pop dx
cmp dl, "["
JNE mismatch
JMP input
end_input:
cmp cx, 0
JNE many_left
mov ah, 9
lea dx, msg_correct
int 21h
lea dx, msg_continue
int 21h
mov ah,1
int 21h
cmp al, "Y"
JNE exit
JMP start
mismatch:
lea dx, msg_mismatch
mov ah,9
int 21h
JMP start
many_left:
lea dx, msg_left_bracket
mov ah,9
int 21h
JMP start
many_right:
lea dx, msg_right_bracket
mov ah,9
int 21h
JMP start
exit:
mov ah,4ch
int 21h
MAIN ENDP
END MAIN
[/code]
Difficulties & Discussion:
Since I have already solved this problem in C, I hadn’t face too much problem for the algorithm to solve this in assembly language. All dificulties I faced was in the syntax of Assembly language. At first,finishing the code,it wasn’t working for some inputs like (a+b)) or (a+b)} for which output will be “TOO MANY RIGHT BRACKETS”. But my code was being redirected to starting position of main procedure because of my silly mistake.Thsi mistake was in line number 83,94 and 104.
Wrong code
[code] pop dx
dec cx
cmp cx,0
JL many_right
cmp dl, "{"
JNE mismatch
JMP input[/code]
Corrected code:
[code]
dec cx
cmp cx,0
JL many_right
pop dx
cmp dl, "{"
JNE mismatch
JMP input
[/code]
For the example (a+b)}
When the last ‘}’ is scanned,then stack is empty.but in the code I have poped from stack,which is an invalid instruction. But actually it is required that,I will first check if the stack is empty or not.If empty,then “too many right brackets”. If not then pop dx and should be checked with the scanned data.It was done in the right side code.
This problem is an application of stack implementation and we have successfully solved this using stack in assembly language.
]]>শহীদ শাকিল নিহন
বিশিষ্ট কমপু প্রেমিক
————