by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int v[10010];
//vector<int>v;
int i,j,n,k,max,price1,a,price2,m,diff,tmp;
while(cin>>n)
{
for(i=0;i<n;i++)
cin>>v[i];
//v.push_back(i);
cin>>m;
max=1000000;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if((v[i]+v[j])== m)
{
diff=abs(v[i]-v[j]);
if(diff<max)
{
max=diff;
price1=v[i];
price2=v[j];
}
}
}
if(price1>price2)
{
tmp=price1;
price1=price2;
price2=tmp;
}
printf("Peter should buy books whose prices are %d and %d.\n\n",price1,price2);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#define pi 2*acos(0)
using namespace std;
int main()
{
double s,a,b,c,tri_area,red_out,red_in;
double area_circum,area_inscribed,area_triangle;
while(scanf("%lf %lf %lf", &a, &b, &c)==3)
{
s=(a+b+c)/2;
tri_area=sqrt(s*(s-a)*(s-b)*(s-c));
red_out=((a*b*c)/(4*tri_area));
red_in=(tri_area/s);
area_circum=(pi*pow(red_out, 2))-tri_area;
area_inscribed=(pi*pow(red_in, 2));
tri_area=tri_area-area_inscribed;
printf("%.4lf %.4lf %.4lf\n", area_circum, tri_area, area_inscribed);
}
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <stdio.h>
int main()
{
long int dn,r,q;
long int bn[10000],i,j;
while(1)
{
scanf("%ld",&dn);
if(dn<0) break;
else if(dn==0) printf("0\n");
else
{
q=dn;
i=0;
while(q>0)
{
bn[i++]=q%3;
q=q/3;
}
i=i-1;
for(j=i;j>=0;j--)
printf("%ld",bn[j]);
printf("\n");
}
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[200];
int n,i,j,l,a;
while(cin>>n)
{
if(n==0) break;
scanf("%s",s);
l=strlen(s);
a=l/n;
for(i = 0; i < l; i += a) {
for(j = i+a-1; j >= i; j--)
printf("%c",s[j]);
}
puts("");
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
string ch1,ch2;
map<string,string>m;
int n,l,i,j,k;
char c1,c2;
cin>>l>>n;
for(i=0;i<l;i++)
{
cin>>ch1>>ch2;
m[ch1]=ch2;
}
for(i=0;i<n;i++){
cin>>ch2;
if(m[ch2]!="") cout<<m[ch2]<<endl;
else{
c1=ch2[ch2.size()-1];
c2=ch2[ch2.size()-2];
if(c1=='y'&&(c2!='a'&&c2!='e'&&c2!='i'&&c2!='o'&&c2!='u'))
{
ch2.erase(ch2.size()-1,1);
cout<<ch2<<"ies"<<endl;
}
else if(c1=='o'||c1=='s'||c1=='x'||(c1=='h'&&c2=='c')||
(c1=='h' && c2=='s'))
cout<<ch2<<"es"<<endl;
else
cout<<ch2<<"s"<<endl;
}
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int func_tion(int n)
{
int j,sum=0;
if(n<10)
return n;
else
{
for(j=0;; j++)
{
sum+=n%10;
n=n/10;
if(n==0)
break;
}
return func_tion(sum);
}
}
int main()
{
int a,n,res,sum,k;
while(cin>>n && n!=0)
{
cout<<func_tion(n)<<endl;
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
using namespace std;
char ch1[10002];
int main()
{
int n,k,m,value[102],nn;
char ch[302];
double s;
scanf("%d",&n);
while(n--)
{
s=0;
scanf("%d\n",&k);
for(int i=0;i<k;i++)
scanf("%c%d\n",&ch[i],&value[i]);
scanf("%d\n",&nn);
for(int i=0;i<nn;i++)
{
gets(ch1);
int l=strlen(ch1);
for(int j=0;j<k;j++)
{
for(int p=0;p<l;p++)
if(ch[j]==ch1[p])
s+=value[j];
}
}
printf("%0.2lf$\n",s/100.00);
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
char m[1002];
int tc, l, n, i, j, r,sum,a[100];
bool flag;
cin>>tc;
while (tc--)
{
scanf("\r");
gets(m);
l = strlen(m);
cin>>n;
for (i = 0; i < n; i++)
cin>>a[i];
flag = false;
for (i = 0; i < n; i++)
{
r= 0;///remainder
for (j = 0; j < l; j++)
r = (r*10 + (m[j]-'0'))% a[i] ;
if (r)
{
flag = true;
break;
}
}
if (flag) printf("%s - Simple.\n", m);
else printf("%s - Wonderful.\n", m);
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
string n,a;
long long s,b,c,d,l;
while(cin>>n)
{
sort(n.begin(),n.end());
a=n;
if(a[0]=='0')
{
for(int i=1;i<n.size();i++)
{
if(a[i]!='0')
{
swap(a[0],a[i]);
break;
}
}
}
reverse(n.begin(),n.end());
b=atoll(n.c_str());
c=atoll(a.c_str());
if(b<c)
swap(b,c);
s=b-c;
d=s/9;
printf("%lld - %lld = %lld = 9 * %lld\n",b,c,s,d);
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b,i,j,x,y;
bool penalty;
while(cin>>n)
{
if(n==0) break;
penalty=false;
for(i=1;i<n;i++)
{
for(j=0;j<=i;j++)
{
if((i*i*i-j*j*j)==n)
{
cout<<i<<" "<<j<<endl;
penalty=true;
break;
}
}
if(penalty==true)
break;
}
if(penalty==false)
cout<<"No solution\n";
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,m,i,b,count;
while(scanf("%lld %lld",&n,&m)==2)
{
if(n==0 && m==0) break;
count=0;
for(i=n;i<=m;i++)
{
b=sqrt(i);
if(i==(b*b))
count++;
}
cout<<count<<endl;
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
long int ary[2000007];
int main()
{
int n,i,j,k;
while (scanf("%ld",&n)==1)
{
if (n==0)
{
break;
}
for (i=0;i<n;i++)
{
scanf("%ld",&ary[i]);
}
sort(ary,ary+n);
for (i=0;i<n;i++)
{
printf("%ld",ary[i]);
if (i<(n-1))
printf(" ");
}
printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include<stdio.h>
int main()
{
long int t,a,b,c,i;
while(scanf("%ld",&t)==1)
{
for(i=1; i<=t; i++)
{
scanf("%ld %ld %ld", &a, &b, &c);
if ((a+b)<=c || (b+c)<=a || (c+a)<=b || a<=0 || b<=0 || c<=0)
printf("Case %ld: Invalid\n",i);
else if(a==b && b==c&&c==a)
printf("Case %ld: Equilateral\n",i);
else if(a==b || b==c || c==a)
printf("Case %ld: Isosceles\n",i);
else
printf("Case %ld: Scalene\n",i);
}
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x1,x2,y1,y2;
while(cin>>x1>>y1>>x2>>y2)
{
if(x1==0 && y1==0 && x2==0 && y2==0)
break;
if(x1==x2 and y1==y2) printf("0\n");
else if( x1==x2 ||y1==y2|| abs(y1-y2)==abs(x1-x2)) printf("1\n");
else if ( abs(y1-y2)!=abs(x1-x2)) printf("2\n");
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc,n,m,x,y;
while(cin>>tc)
{
if(tc==0) break;
cin>>n>>m;
for(int i=0;i<tc;i++)
{
cin>>x>>y;
if(x==n || y==m) cout<<"divisa\n";
else if(x>n and y>m) cout<<"NE\n";
else if(x<n and y>m) cout<<"NO\n";
else if(x<n and y<m) cout<<"SO\n";
else if(x>n and y<m)
cout<<"SE\n";
}
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
char l,s[105];
int c,j,t,i;
scanf("%d%*c",&t);
for(i=1;i<=t;i++)
{
c=0;
gets(s);
l=strlen(s);
for(j=0;j<l;j++)
{
if((s[j]=='a')||(s[j]=='d')||(s[j]=='g')||(s[j]=='j')||(s[j]=='m')||(s[j]=='p')||(s[j]=='t')||(s[j]=='w')||(s[j]==' '))
c+=1;
else if((s[j]=='b')||(s[j]=='e')||(s[j]=='h')||(s[j]=='k')||(s[j]=='n')||(s[j]=='q')||(s[j]=='u')||(s[j]=='x'))
c+=2;
else if((s[j]=='c')||(s[j]=='f')||(s[j]=='i')||(s[j]=='l')||(s[j]=='o')||(s[j]=='r')||(s[j]=='v')||(s[j]=='y'))
c+=3;
else if((s[j]=='s')||(s[j]=='z'))
c+=4;
}
printf("Case #%d: %d\n",i,c);
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc,cases=0,j,r;
char s[1000],c;
cin>>tc;
while(tc--)
{
scanf("\r");
gets(s);
int l=strlen(s);
printf("Case %d: ",++cases);
for(int i=0;i<l;i++)
{
r=0;
if(s[i]>='A'&&s[i]<='Z')
c=s[i];
else
{
while(s[i]>='0'&& s[i]<='9')
{
r=r*10+s[i]-'0';
i++;
}
i--;
for( j=0;j<r;j++)
printf("%c",c);
}
}
printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t = 0,i,n;
cin >> t;
while(t--)
{
int n = 0;
cin >> n;
n *= 567;
n /= 9;
n += 7492;
n *= 235;
n /= 47;
n-= 498;
n/=10;
n%=10;
printf("%d\n",abs(n));
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
struct and union in C
These both declare same and uses are almost same;
just the difference when use
struct then need to declare with ‘struct’ keyword
struct student
{
int roll;
float age;
};
when use union then declare as
union student
{
int roll;
float age;
};
There is also a strong difference between struct and union
struct size measure by sum of all the used datatypes in struct;
like
struct student
{
int roll;
float age;
};
for this student struct datatype size is 6 bytes i.e ( 2 + 4);
union student
{
int roll;
float age;
};
where union size measure by the largest data size like in this example
student union data types size is 4 bytes.
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int p,b,h,w,price,i,a,j,s;
while(scanf("%d %d %d %d",&p,&b,&h,&w)==4)
{
int cost=15000000;
for(i=0;i<h;i++)
{
scanf("%d",&price);
for(j=0;j<w;j++)
{
scanf("%d",&a);
s=0;
if(a>=p)
{
s=price*p;
if(cost>s)
cost=s;
}
}
}
if(cost<=b)
cout<<cost<<endl;
else
cout<<"stay home"<<endl;
}
return 0;
}