পৃষ্ঠাসমূহ

সোমবার, ১ ফেব্রুয়ারী, ২০১৬

Jan’s LightOJ :: 1249 - Chocolate Thief Solution

1249 - Chocolate Thief
Solution in c++:



#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct student
{
string name;
int volume;
};

bool compare(student a,student b)
{
return a.volume<b.volume;

}
int main()
{

int t,n,height,width,depth;
string name;
cin>>t;
student st,stThief,stLost;
for(int i = 0; i < t; i++)
{
vector<student> Students;
cin>>n;
for(int i = 0; i<n; i++)
{
cin>>name>>height>>width>>depth;
st.name = name;
st.volume = height*width*depth;
Students.push_back(st);
}
sort(Students.begin(),Students.end(),compare);
cout<<"Case "<<i+1<<": ";
stLost = Students[0];
stThief = Students[n-1];
if(stThief.volume==stLost.volume)
cout<<"no thief"<<endl;
else
cout<<stThief.name<<" took chocolate from "<<stLost.name<<endl;

}

}


২টি মন্তব্য:

  1. #include
    using namespace std;

    int main(){

    int t,a=1;
    cin >> t;
    while(t--){

    int n,k=0,found=0;
    cin >> n;

    string s[n],thief,victim;

    int l[n],w[n],h[n],vol[n],consv;

    for(int i = 0 ; i < n ; i++){
    cin >> s[i] >> l[i] >> w[i] >> h[i];
    vol[i]=l[i]*w[i]*h[i];
    }

    for(int i = 1 ; i < n ; i++){
    if(vol[i] == vol[i-1]){
    consv=vol[i];
    break;
    }
    }

    for(int j = 0 ; j < n ; j++){
    if(vol[j] > consv){
    thief=s[j];
    found++;
    }
    if(vol[j] < consv){
    victim=s[j];
    }
    }

    if(found==0) printf("Case %d: no thief\n",a);
    else cout << "Case " << a << ": " << thief << " took chocolate from " << victim << endl;

    //else printf("%s took chocolate from %s\n",thief,victim);
    a++;
    }

    return 0;
    }

    উত্তরমুছুন
  2. ei code tar bhul kothay? wrong answer bolche :/

    উত্তরমুছুন