Thursday, November 10, 2016

Uva 10071 - Back to High School Physics

#include <iostream>
using namespace std;
int main() {
int v,t;
while(cin >> v >> t) {
cout  <<  2*v*t  <<  endl;
}
return 0;
}

Uva 10055 - Hashmat the Brave Warrior

#include<iostream>
using namespace std;
int main()
{
unsigned long x,y;
while(cin >> x >> y){
if(y>x) cout << y-x << endl;
else cout << x-y << endl;
}
return 0;
}

Uva 10050 - Hartals

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,j,i,k,l,p,l1=0;
cin>>n;
while(n--) {
cin >> m >> p;
int ad[m],bd[p];
for( i = 1 ; i <= m ; i++ ) ad[i]=0 ;
for( i = 1 ; i<= p ; i++ ) cin >> bd[i] ;
for( i = 1 ; i <=p ; i++ )
for( j = bd[i] ;  j <=m ; j += bd[i] )
ad[j]=1;
l=0;
for( i = 1 ; i <=m ; i++ )
if(ad[i]==1 && (i-6)%7!=0 && i%7!=0)l++;
cout << l << endl ;
     }
return 0;
   }

Uva 10041 - Vito's Family

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i,j,ad[501],k;
vector<int>v;
cin >> n;
while(n--){
cin >> m;
for( i = 0 ; i < m ; i++ ) {
cin >> k;
v.push_back(k);
}
unsigned long t_v = 5000*30000;
for ( i = 0 ; i < m ; i++ ) {
unsigned long c = 0;
for ( j = 0; j < m; j++) {
c += abs (v[i] - v[j]);
}
t_v = min(t_v,c);
}
cout  << t_v  << endl;
v.clear();
}
return 0;
}

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;
}