Posts

Showing posts from April, 2019

UVA 11059

My 100th UVA    :D #include<bits/stdc++.h> using namespace std; int main() {     int a,b[20],d=0,f=0;     long long int c=1,e[10000];     while(cin>>a)     {         d++;         for(int i=0; i<a; i++)         {             cin>>b[i];         }         for(int j=0; j<a; j++)         {             for(int k=j; k<a; k++)             {                 if(b[k]==0)                 {                     break;                 }                 c=c*b[k];         ...

UVA 11057

Not effective,as time kills #include<bits/stdc++.h> using namespace std; int main() {     int a,b[10001],c,d=0,e=0,f=0,g=1000001;     while(cin>>a)     {         for(int i=0; i<a; i++)         {             cin>>b[i];         }         cin>>c;         for(int i=0; i<a; i++)         {             for(int j=0; j<a; j++)             {                 f=abs(b[i]-b[j]);                 if(b[i]+b[j]==c && f<=g)                 {                     d=b[i];                     ...

UVA 11834

After of struggling of many days,not able to find any solution and seek ones answer: #include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d,e=0,f=0,g=0,h=0;     while(cin>>a>>b>>c>>d)     {         if(a+b+c+d==0)         {             break;         }         else         {             e=c+d;             f=a-e;             g=b-e;             h=f*f+g*g;             if(h>=e*e && 2*max(c,d)<=min(a,b))             {                 cout<<"S"<<endl;             }         ...

UVA 11805

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d,e=0,f=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c>>d;         e=d%b;         f=e+c;         if(f<=b){         cout<<"Case "<<i+1<<": "<<f<<endl;         }         else         {             f=e-(b-c);             cout<<"Case "<<i+1<<": "<<f<<endl;         }         e=0;         f=0;     }     return 0; }

UVA 11743

#include<bits/stdc++.h> using namespace std; int main() {     int a,c=0,sum=0,d=0,e=0,sum1=0;     char b[100];     cin>>a;     getchar();     for(int i=0; i<a; i++)     {         gets(b);         for(int j=0; b[j]!=' '; j++)         {             if(j%2==0)             {                 c=b[j]-'0';                 c=c*2;                 d=c/10;                 e=c%10;                 sum=sum+d+e;                 c=0;                 d=0;                 e=0; ...

UVA 11734

Two hours of midnight experiment and done :D #include<bits/stdc++.h> using namespace std; int main() {     int b,d=0,e=0,m=-1,n=-1;     char a[100],c[100],x[100],y[100],o[100],p[100];     cin>>b;     getchar();     for(int i=0; i<b; i++)     {         gets(a);         gets(c);         if(strcmp(a,c)==0)         {             cout<<"Case "<<i+1<<": Yes"<<endl;         }         else if(strcmp(a,c)!=0)         {             d=strlen(a);             e=strlen(c);             for(int j=0; j<d; j++)             {                 if(a[j]!=' ') ...

UVA 11716

#include<bits/stdc++.h> using namespace std; int main() {     int a,c=0,d=0;     char b[10010];     cin>>a;     getchar();     for(int i=0; i<a; i++)     {         gets(b);         c=strlen(b);         d=sqrt(c);         if(d*d!=c)         {             cout<<"INVALID"<<endl;         }         else if(d*d==c)         {             for(int j=0; j<d; j++)             {                 for(int k=j; k<c; k+=d)                 {                     cout<<b[k];           ...

UVA 11677

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d,e=0,f=0;     while(cin>>a>>b>>c>>d)     {         if(a==0 && b==0 && c==0 && d==0)         {             break;         }         if(a==0)         {             a=24;         }         if(c==0)         {             c=24;         }         if(a<c && b>=d)         {             f=abs(60-b+d);             e=abs(a+1-c)*60;             e=e+f;         }         if(a...

UVA 11650

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d=0,e=0;     cin>>a;     for(int i=0; i<a; i++)     {         scanf("%d:%d",&b,&c);         if(b<11 && c==0)         {             e=12-b;             d=0;         }         else if(b<11 && c>0 && c<60)         {             e=12-b-1;             d=60-c;         }         else if(b==11 && c>0)         {             e=12;             d=60-c;         }         else if(b==12 && c<60 ...

UVA 11636

#include<bits/stdc++.h> using namespace std; int main() {     int a,b[10020],c,k=2,d=0,e=1;     for(int i=2; i<=10000; i++)     {         e+=e;         for(int j=1; j<=e; j++)         {             k++;             if(k==10001)             {                 break;             }             b[k]=i;             //cout<<b[k]<<" "<<k<<endl;         }         if(k==10001)             {                 break;             }     }     b[0]=0;     b[1]=0;   ...

UVA 11946

#include<bits/stdc++.h> using namespace std; int main() {     char b[1100];     int a,c,d=0;     cin>>a;     getchar();     for(int i=0; i<a; i++)     {         if(d==1){         cout<<endl;         }         d=1;         while(gets(b)){         if(strlen(b)==0) break ;     for(int j=0; j<strlen(b); j++)     {         if(b[j]=='1')         {             b[j]='I';         }         if(b[j]=='2')         {             b[j]='Z';         }         if(b[j]=='3')         {             b[j]='E'; ...

UVA 12342

#include<bits/stdc++.h> using namespace std; int main() {     long long int a,b,d;     double c;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         if(b>180000.0 && b<=480000.0)         {             c=((b-180000.0)*0.1);         }         else if(b>480000.0 && b<=880000.0)         {             c=30000.0+((b-480000.0)*0.15);         }         else if(b>880000.0 && b<=1180000.0)         {             c=30000.0+(400000.0*.15)+((b-880000.0)*.20);         }         else if(b>1180000.0)         {     ...

UVA 11850

#include<bits/stdc++.h> using namespace std; int flag=0; int main() {     int a,b[1423],c=0;     while(cin>>a)     {         if(a==0)         {             break;         }         else         {             for(int i=0; i<a; i++)             {                 cin>>b[i];             }             sort(b,b+a);             for(int j=0; j<a-1; j++)             {                 c=abs(b[j]-b[j+1]);                 if(c<=200 && 1422-b[a-1]<=100)           ...

UVA 11152

#include<bits/stdc++.h> using namespace std; int main() {     double a,b,c,d=0,e=0,f=0,x=0,g=0;     while(cin>>a>>b>>c){     d=(a+b+c)/2.0;     x=sqrt(d*(d-a)*(d-b)*(d-c));     e=M_PI*pow((x/d),2);     f=x-e;     g=(M_PI*pow((a*b*c)/(4*x),2))-x;     printf("%.4lf %.4lf %.4lf\n",g,f,e);     d=0;     e=0;     f=0;     g=0;     x=0;     }     return 0; }

UVA 11185

#include<bits/stdc++.h> using namespace std; int main() {     long long int a,b[100],i=0,c=0;     while(cin>>a)     {         if(a<0)         {             break;         }         else         {             c=a;             while(c!=0)             {                 b[i]=c%3;                 c=c/3;                 i++;             }             if(a==0)             {                 cout<<"0"<<endl;             } ...

UVA 12459

#include<bits/stdc++.h> using namespace std; int main() {     long long int a,b[80];     b[0]=1;     b[1]=2;     b[2]=3;     for(int i=3; i<80; i++)     {         b[i]=b[i-1]+b[i-2];     }     while(cin>>a)     {         if(a==0)         {             break;         }         else         {             cout<<b[a-1]<<endl;         }     }     return 0; }

UVA 12250

#include<bits/stdc++.h> using namespace std; int main() {     char a[14];     int b=0;     while(cin>>a)     {         if(strcmp(a,"#")==0)         {             break;         }         else         {             b++;             if(strcmp(a,"HELLO")==0)             {                 cout<<"Case "<<b<<": ENGLISH"<<endl;             }             else if(strcmp(a,"HOLA")==0)             {                 cout<<"Case "<<b<<": SPANISH"<<endl;             } ...

UVA 11777

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d,e,f[3],g=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c>>d>>e>>f[0]>>f[1]>>f[2];         sort(f,f+3);         g=b+c+d+e+((f[1]+f[2])/2);         if(g>=90)         {             cout<<"Case "<<i+1<<": A"<<endl;         }         else if(g>=80 && g<90)         {             cout<<"Case "<<i+1<<": B"<<endl;         }         else if(g>=70 && g<80)         {             cout<<"Case "<<i+1...

UVA 11713

#include<bits/stdc++.h> using namespace std; int main() {     int a,d=0,e=0,flag=0;     char b[20],c[20];     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         cin>>c;         d=strlen(b);         e=strlen(c);         for(int j=0; j<d; j++)         {             if(b[j]=='a' || b[j]=='e' || b[j]=='i' || b[j]=='o' || b[j]=='u')             {                 b[j]=0;                 c[j]=0;             }         }         for(int k=0; k<e; k++)         {             if(b[k]!=c[k])     ...

UVA 900

#include<bits/stdc++.h> using namespace std; int main() {     long long int a,b[51];     b[0]=0;     b[1]=1;     b[2]=2;     b[3]=3;     for(int i=4; i<=50; i++)     {         b[i]=b[i-1]+b[i-2];     }     while(cin>>a)     {         if(a==0)         {             break;         }         else         {             cout<<b[a]<<endl;         }     }     return 0; }

UVA 11462

#include<bits/stdc++.h> using namespace std; long int b[2000005]; int main() {     long long int a,c=0;     while(cin>>a)     {         if(a==0)         {             break;         }         else         {             for(long long int i=0; i<a; i++)             {                 cin>>b[i];             }             sort(b,b+a);             for(long long int i=0; i<a; i++)             {                 cout<<b[i];                 if(i<a-1)           ...

UVA 12157

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d=0,e=0;     double Mile=0,Juice=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         for(int j=0; j<b; j++)         {             cin>>c;             Mile=Mile+(ceil(c/30.0)*10);             Juice=Juice+(ceil(c/60.0)*15);             if(c%30==0)             {                 d++;             }             if(c%60==0)             {                 e++;             }         ...

UVA 12751

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d,e[10000],l=0,sum=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c>>d;         for(int j=1; j<=b; j++)         {             e[l]=j;             l++;         }         for(int k=d; k<d+c; k++)         {             e[k-1]=0;         }         for(int m=0; m<l; m++)         {             sum=sum+e[m];         }         cout<<"Case "<<i+1<<": "<<sum<<endl;         l=0;         sum=0;   ...

UVA 12854

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d,e,a1,b1,c1,d1,e1;     while(cin>>a>>b>>c>>d>>e>>a1>>b1>>c1>>d1>>e1)     {         if(a+a1==1 && b+b1==1 && c+c1==1 && d+d1==1 && e+e1==1)         {             cout<<"Y"<<endl;         }         else         {             cout<<"N"<<endl;         }         a=0;         b=0;         c=0;         d=0;         e=0;         a1=0;         b1=0;         c1=0;         d1=0;       ...

UVA 12895

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c=0,e=0,d=0,f=0,g=1;     cin>>b;     for(int i=0; i<b; i++)     {         cin>>a;         c=a;         while(c!=0)         {             c=c/10;             e++;         }         c=0;         c=a;         while(c!=0)         {             f=c%10;             c=c/10;             for(int j=0; j<e; j++)             {                 g=g*f;             }             d=d+g;   ...

UVA 11388

#include<bits/stdc++.h> using namespace std; int main() {     long long int a,b,c,d=0,e=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c;         d=__gcd(b,c);         e=(b*c)/d;         if(c%b==0)         {             cout<<d<<" "<<e<<endl;         }         else         {             cout<<"-1"<<endl;         }         d=0;         e=0;     }     return 0; }

UVA 12578

#include<bits/stdc++.h> using namespace std; int main() {     int a,b;     double c=0,d=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         c=M_PI*pow((b/5.0),2);         d=(b*(0.6*b))-c;         printf("%.2f %.2f\n",c,d);         c=0;         d=0;     }     return 0; }

UVA 12289

#include<bits/stdc++.h> using namespace std; int main() {     char b[20];     int a,c=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         c=strlen(b);         if(c==5)         {             cout<<"3"<<endl;         }         else if((b[0]=='t' && b[1]=='w') || (b[0]=='t' && b[2]=='o') || (b[1]=='w' && b[2]=='o'))         {             cout<<"2"<<endl;         }         else if((b[0]=='o' && b[1]=='n') || (b[0]=='o' && b[2]=='e') || (b[1]=='n' && b[2]=='e'))         {             cout<<"1"<<endl;   ...

UVA 11417

#include<bits/stdc++.h> using namespace std; int main() {     long long int a,sum=0;     while(cin>>a){     if(a==0)     {         break;     }     else     {         for(long long int i=1; i<a; i++)         {             for(long long j=i+1; j<=a; j++)             {                 sum=sum+__gcd(i,j);             }         }         cout<<sum<<endl;         sum=0;     }     }     return 0; }

UVA 12502

Dont copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a,b,c,d;     float e=0,f=0,h=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c>>d;         e=(b+c)/3.0;         if(b>e){         f=d/e*1.0;         h=(abs(b-e)*f);         printf("%.0f\n",h);         e=0;         f=0;         h=0;         }         else         {             printf("0\n");         }     }     return 0; }

UVA 12700

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a,c,d,Bangladesh=0,World=0,Tie=0,Abandon=0;     char b[11];     cin>>a;     for(int i=0; i<a; i++)     {         cin>>c;         for(int j=0; j<c; j++)         {             cin>>b[j];             if(b[j]=='B')             {                 Bangladesh++;             }             else if(b[j]=='W')             {                 World++;             }             else if(b[j]=='T')           ...

UVA 113

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     double a,b,c=0;     while(cin>>a>>b)     {         c=pow(b,1.0/a);         printf("%.0f\n",c);         c=0;     }     return 0; }

UVA 12468

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a,b;     while(cin>>a>>b)     {         if(a==-1 && b==-1)         {             break;         }         else         {             if(abs(a-b)>50)             {                 cout<<abs(100-abs(a-b))<<endl;             }             else if(abs(a-b)<=50)             {                 cout<<abs(b-a)<<endl;             }         }     }     return 0; }

UVA 11479

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     long long int a,b,c,d=0,e;     cin>>e;     for(int i=0; i<e; i++)     {         cin>>a>>b>>c;         if(a>0 && a==b && b==c)         {             d++;             cout<<"Case "<<d<<": Equilateral"<<endl;         }         else if(a>0 && b>0 && c>0 && a+b>c && b+c>a && c+a>b && ((a==b && b!=c) || (b==c && c!=a) || (a==c && c!=b)))         {                 d++;                 cout<<"Case "<<d<<": Isosce...

UVA 11715

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     double a,b,c,d,s=0,ac=0,t=0,u=0,v=0;     int x=0;     while(cin>>a)     {         if(a==0)         {             break;         }         else{             cin>>b>>c>>d;             if(a==1)             {                 x++;                 s=0.5*(b+c)*d;                 ac=(c-b)/d;                 printf("Case %d: %.3f %0.3f\n",x,s,ac);             }             else if(a==2)     ...

UVA 12461

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a;     while(cin>>a)     {         if(a==0)         {             break;         }         else         {             cout<<"1/2"<<endl;         }     }     return 0; }

UVA 10370

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a,b,c[1000],d=0,sum=0;     float sum1=0,sum2=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         for(int j=0; j<b; j++)         {             cin>>c[j];             sum=sum+c[j];         }         sum1=sum*1.0/b;         for(int j=0; j<b; j++)         {             if(c[j]>sum1)             {                 d++;             }         }         sum2=(d*1.0/b)*100;         printf("%....

UVA 12646

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a,b,c;     while(cin>>a>>b>>c)     {         if(a==b && b==c)         {             cout<<"*"<<endl;         }         else if(a==b && b!=c)         {             cout<<"C"<<endl;         }         else if(a==c && a!=b)         {             cout<<"B"<<endl;         }         else if(a!=b && b==c)         {             cout<<"A"<<endl;         }     }     return 0;...

UVA 10018

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     long long int a,b,c,rev=0,sum=0,d=0,e=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         c=b;         while(rev!=b)         {             rev=0;             while(c!=0)             {                 rev=rev*10;                 rev=rev+c%10;                 c=c/10;             }             if(b==rev)             {                 d++;              ...

UVA 12704

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     float e=0,f=0,g=0;     int a,b,c,d;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c>>d;         e=sqrt(pow(b,2)+pow(c,2));         f=d-e;         g=d+e;         printf("%0.2f %.2f\n",f,g);         e=0;         f=0;         g=0;     }     return 0; }

UVA 694

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     long long int a,b,c=0,d=0,e=0,f=0;     while(cin>>a>>b)     {         c=a;         f++;         if(a<0 && b<0)         {             break;         }         else         {             while(c!=1 && c<=b)             {                 d++;                 if(c%2==0)                 {                     c=c/2;                     //d++;       ...

UVA 11044

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     long long a,b,c,d=0,e=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b>>c;         d=b/3;         e=c/3;         cout<<d*e<<endl;         d=0;         e=0;     }     return 0; }

UVA 10299

Don't copy without trying. # include <bits/stdc++.h> using namespace std ; int status[ 100000000 / 32 ]; bool Check ( int N, int pos) { return ( bool )(N & ( 1 <<pos));} int Set ( int N, int pos) { return N=N | ( 1 <<pos);} int arr[ 100000 ]; long long int l= 0 ,a,b= 32000 ,n; void sieve () { long long int i,j,sqrtN; sqrtN = int ( sqrt ( b ) ); for ( i= 3 ; i<=sqrtN; i+= 2 ) { if ( Check(status[i/ 32 ],i% 32 )== 0 ) { for (j=i*i; j<=b; j+= 2 *i) { status[j/ 32 ]=Set(status[j/ 32 ],j% 32 ); } } } arr[ 0 ]= 2 ; l= 1 ; for (i= 3 ;i<=b;i+= 2 ){ if (Check(status[i/ 32 ],i% 32 )== 0 ){ arr[l]=i; l++; } } } int EulerPHI ( long long int a) { int res=a; int sqrtA= sqrt (a); for ( int i= 0 ; i<l && arr[i]<=sqrtA; i++) { int count= 0 ; /*if(Check(status...

UVA 10179

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int status[100000000/32]; bool Check(int N,int pos){return (bool)(N & (1<<pos));} int Set(int N,int pos){ return N=N | (1<<pos);} int arr[100000]; long long int l=0,a,b=32000,n; void sieve() {      long long int i,j,sqrtN;      sqrtN = int( sqrt( b ) );      for( i=3; i<=sqrtN; i+=2 )      { if( Check(status[i/32],i%32)==0) { for(j=i*i; j<=b; j+=2*i) { status[j/32]=Set(status[j/32],j%32); } }     }     arr[0]=2;     l=1;      for(i=3;i<=b;i+=2){             if(Check(status[i/32],i%32)==0){                 arr[l]=i;                 l++;         }      } } int EulerPHI(long long...

UVA 458

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     char a[10000];     int b=0;     while(cin>>a)     {         b=strlen(a);         for(int i=0; i<b; i++)         {             a[i]=a[i]-7;         }         cout<<a<<endl;         b=0;     }     return 0; }

UVA 12403

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     long long int a,sum=0,c;     char b[7];     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         if(strcmp(b,"donate")==0)         {             cin>>c;             sum=sum+c;         }         else if(strcmp(b,"report")==0)         {             cout<<sum<<endl;         }     }     return 0; }

UVA 11764

Don't copy without trying. #include<bits/stdc++.h> using namespace std; int main() {     int a,b,c[50],d=0,e=0,f=0;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         for(int j=0; j<b; j++)         {             cin>>c[j];         }         d=c[0];         for(int j=0; j<b-1; j++)         {             if(c[j+1]>d)             {                 d=c[j+1];                 e++;             }             if(c[j+1]<d)             {             ...