Sunday, May 29, 2016

UVA 11713

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;

#define dbug(x) cout<<">"<<x<<endl;



int main()
{
 int i,j,n,vowel,con;
 vector<char>s1,s2;
 string a,a1;
 
 while(cin>>n)
 {
  while(n--)
  {
   cin>>a;
   cin>>a1;
   
   int len=a.length();
   int len1=a1.length();
   
    s1.clear();
    s2.clear();
    vowel=0;
 
   if(len==len1)
   {
    for(i=0; i<len; i++)
    {
     
     if((a[i]=='a' || a[i]=='e' || a[i]=='i' || a[i]=='o' || a[i]=='u') && (a1[i]=='a' || a1[i]=='e' || a1[i]=='i' || a1[i]=='o' || a1[i]=='u')) {
      //nothing :D
     }
     
     else {
      s1.push_back(a[i]);
      s2.push_back(a1[i]);
     }

    }
    
    for(j=0; j<s1.size(); j++)
    {
     if(s1[j]==s2[j]) vowel++;
    }
    
     if(vowel==s1.size()) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
    
   }
   
   else cout<<"No"<<endl;
  }
  
 }
 
 return 0;
}

Tuesday, May 24, 2016

Perfect Numbers Code in C++

#include<iostream>
#include<cmath>

using namespace std;

int isPerfect(int n)
{
 int i,sum;
 sum=0;
 for(i=1; i<n; i++)
 {
  if(n%i==0) sum+=i;
 }
 
 return sum;
}

int main()
{
 int n;
 cin>>n;
 if(isPerfect(n)==n) cout<<"This is perfect"<<endl;
 else cout<<"Not perfect"<<endl;
 
 cout<<"Some perfect nums are :D \n";
 for(int i=2; i<100; i++)
 {
  if(isPerfect(i)==i) cout<<i<<" ";
 }

 return 0;
}

Saturday, May 21, 2016

UVA 10323

import java.math.*;
import java.util.*;

public class Main {
 public static void main(String args[]){

  Scanner sc = new Scanner(System.in);
  BigInteger a , r;
  int n;

  while(sc.hasNextInt()){

   n = sc.nextInt();

   if(n < 0){
    n = Math.abs(n);
    if(n%2 == 0)
     System.out.println("Underflow!");
    else System.out.println("Overflow!");
   }

   else if(n < 8)
    System.out.println("Underflow!");

   else if(n >= 14)
    System.out.println("Overflow!");

   else{
    a = new BigInteger("1");
    r = new BigInteger("1");
    int i = 1;

    while(i <= n){
     r = r.multiply(a);
     a = a.add(new BigInteger("1"));
     i++;
    }

    System.out.println(r);
   }
  }

 }
}

CF 546A

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

int main()
{
    long long k,n,w,ans = 0;
    cin >> k >> n >> w;
    for(int i = 1; i <= w; i++){
        ans += i*k;
    }
    ans-=n;
    if(ans <= 0)cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

CF 96A

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int flag, cnt;
    char s[105];
    scanf("%s", s);
    cnt=flag=0;
    for(int i=1; i<strlen(s); i++) {
        if(s[i]==s[i-1]) cnt++;
        else cnt=0;
        if(cnt==6) {
            flag=1;
            printf("YES");
            break;
        }
    }
    if(flag==0) printf("NO");
    return 0;
}

CF 236A

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define sf scanf
#define pf printf
typedef long long ll;

int main()
{
    char s[105];
    cin >> s;
    int len = strlen(s);
    sort(s, s+len);
    int count =0;
    for(int i=0; i<len; i++)
    {
        if(s[i] != s[i+1])
        {
            count++;
        }
    }
    if(count%2==0)
    {
        pf("CHAT WITH HER!\n");
    }
    else
    {
        pf("IGNORE HIM!\n");
    }
}

CF 4A

#include<iostream>
#define dbug(x) cout<<">"<<x<<endl;

using namespace std;

int main()
{
 int index,i;
 long long a[37];
 a[0]=1;
 
 for(i=1; i<=36; i++)
 {
  a[i]=a[i-1]*2;
  if(a[i]==8192) a[i]=a[i]-100;
  //dbug(a[i]);
 }
 
 while(cin>>index)
 {
  cout<<a[index]<<endl;
 }
}

CF 617A

#include<iostream>
#define lld long long
#define dbug(x) cout<<">"<<x<<endl

using namespace std;

int main()
{
 long long x;
 long long hp=5;
 
 while(cin>>x)
 {
  if(x%hp==0) cout<<x/hp<<endl;
  else cout<<(x/hp)+1<<endl;
  
   }
   
   return 0;
}

CF 231A

#include<iostream>
#define pf printf
#include<cstdio>
#define dbug(x) cout<<">"<<x<<endl


using namespace std;

int main()
{
 int a,i,sum,t;
 int cnt=0;
 while(cin>>t)
 {
  
  while(t--)
  {
   sum=0;
   for(i=0; i<3; i++)
   { 
    cin>>a;
    sum+=a;
   }
   if(sum>=2) cnt++;
  }
  cout<<cnt<<endl;
  cnt=0;
 }
 
 
 return 0;
}

CF 282A

#include<iostream>
#include<cstring>
#define debug(x) cout<<">"<<x<<endl;

using namespace std;

int main()
{
 int n,x;
 string s;
 
 while(cin>>n)
 {
  x=0;
  while(n--)
  {
   cin>>s;
   if(s=="X++" || s=="++X") x++;
   else if(s=="X--" || s=="--X") x--;
  }
  cout<<x<<endl;
 }
 
 return 0;
}

CF 122A

#include<iostream>
#define dbug(x) cout<<">"<<x<<endl;
#include<vector>

using namespace std;

bool isLucky(int n)
{
 int digit;
 while(n!=0)
 {
  digit= n%10;
     if(digit!=7 && digit!=4) return false;
     n=n/10;
 }
 
 return true;
}



int main()
{
 int i,x,j,m,temp;
 vector<int>v;

 for(i=4; i<=500; i++)
 {
  if(isLucky(i)) {
   temp=i;
   v.push_back(temp);
  }
  
 }
 
 while(cin>>x)
 {
  int si;
  if(isLucky(x)){
    cout<<"YES"<<endl;
  }
  
  else{
   
   si=0;
   for(i=0; i<v.size(); i++)
   {
    if(x%v[i]==0){
     si=1;
     break; 
    }
   }
   
   if(si==1) cout<<"YES"<<endl;
   else if(si==0) cout<<"NO"<<endl;
  }
 }
 
 return 0;
}

CF 71A

#include<iostream>
#include<cstring>

using namespace std;

int main()
{
 int n,i,l;
 string a;
 
 while(cin>>n)
 {
  while(n--)
  {
   cin>>a;
   l=a.size();
   if(l>10)
   {
    cout<<a[0]<<(l-2)<<a[l-1]<<endl; 
   }
   else cout<<a<<endl;
   
   
  }
 }
 return 0;
}

CF 118A

#include<cstring>
#include<iostream>
#include<vector>
#include<ctype.h>

using namespace std;

int main()
{
 char a[101];
 vector<char>con;
 int i;
 
 while(cin>>a)
 {
  con.clear();
  int l=strlen(a);
  for(i=0; i<l; i++)
  {
   if(a[i]=='A' || a[i]=='a' || a[i]=='I' || a[i]=='i' || a[i]=='e' || a[i]=='E' || a[i]=='o' || a[i]=='O'|| a[i]=='U' || a[i]=='u' || a[i]=='y' || a[i]=='Y')
   {
    continue;
   }
   else {
    char c=tolower(a[i]);
    con.push_back(c);
   }
  }
  
  for(i=0; i<con.size(); i++)
  {
   char cc;
   cc=con[i];
   cout<<"."<<con[i];
  }
  cout<<endl;
 }
 
 return 0;
}

Tuesday, May 17, 2016

UVA 10494

import java.math.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {

        try {
            Scanner in = new Scanner(System.in);

            while (in.hasNext()) {
                BigInteger n1 = new BigInteger(in.next());
                String op = in.next();
                BigInteger n2 = new BigInteger(in.next());
                BigInteger res = new BigInteger("0");

                if (op.equals("/")) res = n1.divide(n2);
                if (op.equals("%")) res = n1.mod(n2);
                System.out.println(res);
            }
        }
        catch (Exception e) {
            System.exit(0);
        }


    }
}

Friday, May 6, 2016

UVA 11879

import java.math.BigInteger;
import static java.math.BigInteger.*;
import java.util.Scanner;


public class Main {

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);
  BigInteger n ,d17;
  d17 = TEN.add(valueOf(7));
  while(true){
   n = sc.nextBigInteger();
   if(n.equals(ZERO))break;
   if(n.mod(d17)==ZERO)System.out.println(1);
   else System.out.println(0);
  }
 }

}

Thursday, May 5, 2016

UVA 12004

    #include <cstdio>
     
    using namespace std;
     
    int main(){
        int T,n;
     
        scanf("%d",&T);
     
        for(int tc = 1;tc <= T;++tc){
            scanf("%d",&n);
     
            long long ans = (long long)n * (n-1);
     
            printf("Case %d: ",tc);
     
            if(ans % 4 == 0) printf("%lld\n",ans / 4);
            else printf("%lld/2\n",ans / 2);
        }
     
        return 0;
    }

UVA 543

#include <cstdio>
using namespace std;

int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
  61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
  139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211,
  223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
  293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379,
  383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461,
  463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563,
  569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,
  647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739,
  743, 751, 757, 761, 769, 773, 787, 797, 809, 811821, 823, 827, 829, 839,
  853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013 };

bool isPrime(int n) {
 for (int i = 0; true; i++) {
  if (primes[i] * primes[i] > n || primes[i] == 1013)
   break;
  if (n % primes[i] == 0)
   return false;
 }
 return true;
}

int main() {
 int n;
 while (scanf("%d", &n), n) {
  for (int i = 1; true; i++) {
   int c1 = primes[i];
   int c2 = n - c1;
   if (isPrime(c2) && c2 % 2 != 0) {
    printf("%d = %d + %d\n", n, c1, c2);
    break;
   }
  }
 }

 return 0;
}