Thursday, November 10, 2016

Uva 10038 - Jolly Jumpers

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,ad[30001],k,k1,bd[30001];
while(cin >> n){
if (n == 0) {
cout << "Not jolly" << endl;
continue;
}
int p=0;
for( i = 0 ; i < n ; i++ ) {
cin >> ad[i];
if(i>0)
bd[i-1]=abs(ad[i]-ad[i-1]);
    }
sort(bd,bd+(n-1));
for( j = 0 ; j < n-1 ; j++ ) {
if(bd[j] == j+1)p++;
else break;
    }
if(p != n-1 ) cout << "Not jolly\n";
else cout << "Jolly\n";
}
return 0;
}

Uva 10035 - Primary Arithmetic

#include<bits/stdc++.h>
using namespace std;
int main()
{
long a,n,i,j,k,l,ca=0,p,b;
while(cin >> a >> b ){
if (a==0 && b==0) break;
ca=p=0;
while(a!=0 || b!=0){
k = a%10,a/=10,l = b%10,b/=10;
if(k+l+p>9) ca++,p=1;
else p=0;
if ((a==0 || b==0) && p==0) break;
}
if(ca==0)cout<<"No carry operation.";
else if(ca==1)cout<<"1 carry operation.";
else cout<" carry operations."
;
cout<
}
return 0 ;
}

Uva 10019- Funny Encryption Method

#include<bits/stdc++.h>
using namespace std;
int bin(int n){
int k=0,l=0;
while(n!=0){
l = n%2,n/=2;
if(l==1)k++;
}
return k;
}
int hex(int n1){
int k1=0,l1=0,p=1;
while(n1!=0){
l1 = n1%10,n1/=10;
k1 += l1*p;
p *= 16;
}
k1 = bin(k1);
return k1;
}
int main()
{
int n,i,j;
cin>>n;
while(n--){
cin>>i;
cout<<bin(i)<<" "<<hex(i)<
}
return 0;
}

Uva 10018 - Reverse and Add

#include<bits/stdc++.h>
using namespace std;
int main()
{
unsigned long x,y,tt;
int n,c,k,l;
string s,s1;
char s2[101],xy[101];
cin >> n;
while(n--){
c=0;
cin >> x;
y = x;
sprintf(xy,"%lu", y);
s1=xy;
sprintf(s2,"%lu", x);
s = s2;
reverse(s.begin(),s.end());
if(s!=s1){
while(s!=s1){
for( int i  =  s1.size()-1 , j = 0 ; i >= 0 ; i--, j++ ) xy[j]=s1[i];
c++;
x = strtoul (s2,NULL,10);
y = strtoul (xy,NULL,10);
x = x+y;
y=x;
s1.clear(),s.clear();
sprintf(xy,"%lu", y);
s1=xy;
sprintf(s2,"%lu", x);
s = s2;
reverse(s.begin(),s.end());
int t2 = s.size();
int t1 = s1.size();
xy[t1]='\0',s2[t2]='\0';
}
cout << c <<  " " << x << endl;
}else{
cout << c <<  " " << x << endl;
}
}
return 0;
}

Uva 10008 - What's Cryptanalysis?

#include<bits/stdc++.h>
using namespace std;
struct Ch{
char cha;
int digit;
}ch[31];
bool cmp(Ch a, Ch b) {
return (a.digit > b.digit);
}
int main()
{
int k,l,j,i,m,n;
string s,s1;
char s2[101];
for( i = 0 ; i < 31 ; i++ )ch[i].digit=0,ch[i].cha=(char)(i+65);
cin >> n;
cin.getline(s2,0);
while(n--){
cin.getline(s2,101);
s = s2;
transform(s.begin(), s.end(), s.begin(), ::toupper);
for( i = 0 ; i < s.size()  ; i++ ) {
if(s[i]>='A' && s[i]<='Z')
ch[s[i]-'A'].digit++;
}
}
stable_sort(ch,ch+26,cmp);
for ( i = 0 ;  i < 31  &&  ch[i].digit > 0 ;  i++ )
printf("%c %d\n",ch[i].cha,ch[i].digit);
return 0;
}

Uva 278 - Chess

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,r,k,Q,K,m,p,ans;
char ch;
cin>>n;
while(n--){
cin>>ch>>m>>p;
if(ch=='r'||ch=='Q')ans = min(m,p);
else if(ch=='K')ans = ((m + 1)/2) * ((p + 1)/2);
else if(ch == 'k') ans = (m * p + 1)/2;
cout << ans << endl;
}
return 0;
}

Wednesday, November 9, 2016

Uri 2253 - Passwords Validator

/*                                CODEMAN
                                  Arif Khan Nihar
                       Uri 2253 - Passwords Validator
                                   date - 10/9/2016

*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
string s;
while(getline(cin,s)) {
string s1 = "";
int u=0,sm=0;
for( int i = 0 ;  i  <  s.size()  ; i++ ) {
if((isupper(s[i])) or (islower(s[i])) or (isdigit(s[i]))){
s1 += s[i];
if(isupper(s[i]))u++;
if(islower(s[i]))sm++;
}else{
break;
}
}
if(s1.size() == s.size() and u>0 and sm>0 and s1.size() > 5 and s1.size() < 33)
cout << "Senha valida.\n";
else
cout << "Senha invalida.\n";
}
return 0;
}

Uri 2203- Crowstorm

/*                                                       CODEMAN
                                                      Arif Khan Nihar
                                                   Uri 2203- Crowstorm
                                                      date - 10/9/2016

*/
#include<bits/stdc++.h>
#define di 1.50
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
double d,t_r,t_x,t_y,x1,x2,y1,y2,v,r1,r2;
while(scanf("%lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&v,&r1,&r2)!=EOF){
t_x = (x2 - x1) * (x2 - x1);
t_y = (y2 - y1) * (y2 - y1);
d = sqrt(t_x + t_y);
d += v * di;
t_r = r1 + r2 ;
cout<<((d<=t_r)? "Y\n" : "N\n");
}
return 0;
}

Tuesday, November 8, 2016

Uri 2311 - Diving

#include<bits/stdc++.h>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
int i,j,n;
float mul,ar_val,sum;
multiset<float>val;
string name;
cin>>n;
while(n--){
cin>>name;
sum = 0.0;
scanf("%f",&mul);
for(i = 0; i<7 ;i++){
cin>>ar_val;
val.insert(ar_val);
}
int p = 0 ;
for(multiset<float>::iterator it = val.begin(); it!=val.end();it++,p++){
if(p != 0 and p != 6)
sum += *it;
}
cout << name ;
printf(" %.2f\n",sum*mul);
val.clear();
}
return 0;
}

Monday, November 7, 2016

UVA 10945.Cpp

#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b,c;
int i,op;
while(getline(cin,a)){
if(a=="DONE")break;
b=""; op =   a.size();  
 for(i=0; i < op ;i++)
if (a[i] >= 'A' && a[i] <= 'Z' || a[i] >= 'a' && a[i] <= 'z')
b.push_back(toupper(a[i]));
string r(b.rbegin(),b.rend());
if(b==r)cout << "You won't be eaten!" << endl;
else cout << "Uh oh.." << endl;
}
return 0;
}

Uri 2029 - Honey Reservoir

#include <stdio.h>
#define PI 3.14
int main()
{
double v, r, h, d, a;
int tmp;
while(scanf("%lf %lf", &v, &d)!=EOF)
{
r = d/2;
a = PI*r*r;
h = v/a;
printf("ALTURA = %.2lf\n",h);
printf("AREA = %.2lf\n",a);
}
return 0;
}

Saturday, November 5, 2016

devskills-Banglawash

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t_f1r,t_s1r,t_f2r,t_s2r,f1_r1,f1_r2,s1_r1,s1_r2,f2_r1,f2_r2,s2_r1,s2_r2,n;
cin>>n;
while(n--){
t_f1r = t_f2r = t_s1r = t_s2r = 0;
cin>>f1_r1>>f1_r2>>s1_r1>>s1_r2;
cin>>f2_r1>>f2_r2>>s2_r1>>s2_r2;
t_f1r = f1_r1+f1_r2,t_s1r=s1_r1+s1_r2,t_f2r=f2_r1+f2_r2,t_s2r=s2_r1+s2_r2;
if(t_f1r > t_s1r && t_f2r > t_s2r) cout<<"Banglawash\n";
else cout<<"Miss\n";
}
return 0;
}

Friday, November 4, 2016

Uri 1015 - Distance between two points

#include
#include

int main()
{
    double x1,x2,y1,y2,root;

    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    root= sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));

    printf("%.4f\n",root);

    return 0;
}

 

Uri 1011 - Sphere

#include

int main()
{
    int R;
    double r;
    scanf("%d",&R);

    r=(4.0/3)*3.14159*R*R*R;

    printf("VOLUME = %.3f\n",r);

    return 0;
}

Uri 2157 - Mirror Sequence

#include

int main() {
    int n,m,i,j,t;
    char ss[101] ;
scanf("%d",&t);
    while(t--){
        scanf("%d %d",&n,&m);
        for(i=n;i<=m;i++)printf("%d",i);
        for(i=m;i>=n;i--){
            sprintf( ss, "%d", i );
             for( j = strlen(ss)-1;j>=0;j--) printf("%c",ss[j]);
        }
        printf("\n");
    }
    return 0;
}

Uri 1006 - Average 2

#include

int main(){
float a,b,c,result;
scanf("%f %f %f",&a,&b,&c);
result=((a*2)+(b*3)+(c*5))/(2+3+5);
printf("MEDIA = %.1f\n",result);
return 0;
}


Uri 1005 - Average 1

#include
int main(){
float a,b,result;
scanf("%f %f",&a,&b);
result=((a*3.5)+(b*7.5))/(3.5+7.5);
printf("MEDIA = %.5f\n",result);
return 0;
}

Uri 1008 - Salary

#include

int main()
{
    int A;
    double b, c,d;


    scanf("%d",&A);
    scanf("%lf %lf",&b,&c);

    d=b*c;

    printf("NUMBER = %d",A);
    printf("\nSALARY = U$ %.2f\n",d);

    return 0;
}

Uri 1010 - Simple Calculate

#include

int main()
{
    int a1,b1,a2,b2;
    double c1,d1,c2,d2;

    scanf("%d %d %lf",&a1,&b1,&c1);
    d1=b1*c1;

    scanf("%d %d %lf",&a2,&b2,&c2);
    d2=b2*c2;

    printf("VALOR A PAGAR: R$ %.2f\n",d1+d2);

    return 0;

}

Uri 1009 - Salary with Bonus

#include

int main()
{
    char n;
    double a,b,total;

    scanf("%s %lf %lf",&n,&a,&b);

    total=(b*15)/100;

    printf("TOTAL = R$ %.2lf\n",total+a);

    return 0;
}

Uri 1002 - Area of a Circle

#include

int main(){
    double R,A;

    scanf("%lf",&R);

    A=3.14159*R*R;

    printf("A=%.4lf\n",A);

    return 0;
}

Uri 1007 Difference

#include

int main()
{
    int A,B,C,D,X,Y;

    scanf("%d %d %d %d",&A,&B,&C,&D);

    X=A*B;
    Y=C*D;

    printf("DIFERENCA = %d\n",X-Y);

    return 0;
}

Uri 1004 - Simple Product

#include

int main()
{
    int A,B;
    scanf("%d %d",&A,&B);

    printf("PROD = %d\n",A*B);

    return 0;

}

Uri 1003 - Simple Sum

#include

int main()
{
    int A,B;
    scanf("%d %d",&A,&B);

    printf("SOMA = %d\n",A+B);

    return 0;

}

Uri 1001 - Extremely Basic

#include

int main() {

    int A,B,X;
    scanf("%d %d",&A,&B);
    X=A+B;

    printf("X = %d\n",X);

    return 0;
}

Thursday, November 3, 2016

Uri 2310 - Volleyball

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
        double s,b,a,s1,b1,a1,t_s=0,t_b=0,t_s1=0,k=0,t_b1=0,k1=0;
        float s_ans,b_ans,a_ans;
        string name;
         cin>>n;
         while(n--){
            cin>>name>>s>>b>>a;
            cin>>s1>>b1>>a1;
                t_s  += s;
                t_s1 += s1;
                    t_b += b;
                    t_b1 += b1;
                    k += a;
                    k1 += a1;

         }
         s_ans = (t_s1*100)/t_s;
         b_ans = (t_b1*100)/t_b;
         a_ans = (k1*100)/k;
         cout<<fixed<<setprecision(2)<<"Pontos de Saque: "<<s_ans<<" %."<<endl;
         cout<<fixed<<setprecision(2)<<"Pontos de Bloqueio: "<<b_ans<<" %."<<endl;
         cout<<fixed<<setprecision(2)<<"Pontos de Ataque: "<<a_ans<<" %."<<endl;

    return 0;
}

Uri 2235 - Walking in Time

#include<bits/stdc++.h>
using namespace std;

int main(){
        int f,v,p;
          cin>>f>>v>>p;
        if(f == p  ||  v == p  ||  f == v  ||  f+v == p  ||  v+p == f  ||  f+p == v)
            cout<<"S"<<endl;
        else
            cout<<"N"<<endl;

    return 0;
}

Uri 2242 - Huaauhahhuahau

/*                                                    CODEMAN
                                                ARIF KHAN NIHAR
                                           Uri 2242 - Huaauhahhuahau
                                                    date -> 1/11/2016

                                            */
#include<bits/stdc++.h>
using namespace std;
bool check_vowel(char ch){
    switch(ch){
        case 'a': return true;
        break;
        case 'e': return true;
        break;
        case 'i': return true;
        break;
        case 'o': return true;
        break;
        case 'u': return true;
        break;
        default : return false;
    }
}
int main(){
      string s,s1,s2;
      cin>>s;
      for(int i = 0;i<s.size();i++){
        if(check_vowel(s[i]))
            s1 += s[i];
      }
      s2 = s1;
      reverse(s2.begin(),s2.end());
      if(s1 == s2)
      cout<<"S"<<endl;
      else
         cout<<"N"<<endl;
    return 0;
}

Uri 2232 - Pascal's Triangle

#include<bits/stdc++.h>
using namespace std;

int main(){
    int  i,j,ca,p=0;
     int sum[32][32];
     sum[1][0] = 1,sum[2][0] = 1, sum[2][1] = 1;

    cin>>ca;
    while(ca--){
          int ans = 3,val;  p = 0;
          cin>>val;
          if(val == 1)ans = 1;
          else if(val == 2) ans = 3;
          else{
     for(i = 3; i<=val ; i++){
        sum [i][0] = 1;
        ans += sum[i][0];
    for(j=1 ; j< i-1 ; j++){
        sum[i][j]  = sum[i-1][j-1] + sum[i-1][j];

        ans += sum[i][j];
    }
   sum[i][j] = 1;
   ans += 1;
}
          }
  cout<<ans<<endl;
}
    return 0;
}