by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
bool vowel(char ch)
{
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U')
return true;
else
return false;
}
int main()
{
char ch,c;
while((ch=getchar()) != EOF) //while(ch=getchar())
{
//if(ch==EOF)
//return 0;
if(isalpha(ch))
{
if(vowel(ch))
{
while(isalpha(ch))
{
printf("value=1 %c",ch);
ch=getchar();
printf("value=2 %c\n",ch);
}
printf("ay\n");
}
/*else
{
c=ch;
ch=getchar();
while(isalpha(ch))
{
printf("%c",ch);
ch=getchar();
}
printf("%cay",c);
}*/
}
//printf("%c",ch);
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[2000];
int t,f,a,c;
while(gets(s))
{
c=0;
for(t=0;s[t]!='\0';t++)
{
if(
((s[t]>='A' && s[t]<='Z') || (s[t]>='a' && s[t]<='z'))&&(s[t+1]<'a'||s[t+1]>'z') && (s[t+1]<'A'||s[t+1]>'Z'))
c++;
}
cout<<c<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <stdio.h>
#include<iostream>
#include<math.h>
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, 811, 821, 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 isprimes(int n)
{
//bool flag=false;
for(int i=0;;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 (cin>>n) {
if(n==0) break;
for (int i = 1;; i++) {
int p1 = primes[i];
int p2 = n - primes[i];
if (isprimes(p1) && isprimes(p2)) {
printf("%d = %d + %d\n", n, p1, p2);
break;
}
}
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
char st[100];
long int a,i,j,ans,sum;
while(scanf("%s",st))
{
sum=0;
j=strlen(st);
for(i=0;i<j;i++)
{
a=st[i]-'0';
ans=a*(pow(2,j-i)-1);
sum+=ans;
}
if(sum==0) break;
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{ float h,m,ans,i,j;
while(scanf("%f:%f",&h,&m)==2)
{
if(h==0 and m==0) break;;
i=h*30+(m/60)*30;
j=m*6;
ans=(i-j);
if(ans<0)
ans=ans*(-1);
if (ans>180)
ans=360-ans;
printf("%.3lf\n",ans);
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
bool flag[20000005];
int List[100000],primes[100000];
int listSize,cnt;
using namespace std;
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
void primeFactorize( int n )
{
listSize = 0;
for( int i = 0;i<cnt and primes[i]<=(int)sqrt(n);i++ )
{
if( n % primes[i] == 0 )
{
while( n % primes[i] == 0 )
{
n /= primes[i];
List[listSize] = primes[i];
listSize++;
}
}
}
if( n > 1 )
{
List[listSize] = n;
listSize++;
}
return ;
}
int main()
{
int n;
sieve(50000);
while(cin>>n) {
// scanf("%d", &n);
//printf(n < 0? "%d = -1 x " : "%d = ", n);
if(n == 0) break;
primeFactorize(fabs(n));
printf(n < 0? "%d = -1 x %d" : "%d = %d", n, List[0]);
for(int i = 1; i < listSize; i++)
printf(" x %d", List[i]);
printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,a[100],l=1,sum,move,av;
while(scanf("%d",&n)==1 )
{
if(n==0) break;
sum=0,move=0;;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
av=sum/n;
for(i=0;i<n;i++)
if(a[i]>av)
move=move+(a[i]-av);
printf("Set #%d\nThe minimum number of moves is %d.\n\n",l,move);
l++;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
bool flag[20000005];
int primes[20000000];
int cnt;
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
int main()
{
int n,i,j,count,l,c;
sieve(33000);
while(scanf("%d",&n)==1)
{
if(n==0)
break;
count=0;
c =0;
for(i=0; i<cnt; i++)
{
for(j=0; j<cnt; j++)
{
if(primes[i]==primes[j]&& primes[i]+primes[j]==n)
{
c++;
}
else if(primes[i]+primes[j]==n)
{
count++;
}
if(primes[i]+primes[j]>n)
break;
}
}
count = count/2 +c;
printf("%d\n",count);
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
long int a[10000];
int main()
{
long int n,i;
while(cin>>n)
{
if(n==0) break;
a[1]=1;
a[2]=2;
for(i=3;i<=n;i++)
{
a[i]=a[i-1]+a[i-2];
}
cout<<a[n]<<'\n';
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,sum;
while(scanf("%lld",&n)==1)
{
sum=(3*((n*n)/2+n)-6);
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
#define MAX 1000008
using namespace std;
bool flag[MAX];
int primes[MAX];
int cnt,a[2000];
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
int main()
{
int n,u,l,pos,c,count,max,k,result,j,i;
sieve(MAX);
cin>>n;
while(n--)
{
pos=0;
cin>>l>>u;
for(int i=0;i<cnt;i++)
{
if(primes[i]>=l)
break;
pos++;
}
memset(a, 0, sizeof(a));
for(j=pos;j<cnt and primes[j+1]<=u;j++)
//a[primes[j+1] - primes[j]]++;
{
a[primes[j+1]-primes[j]]++;
}
count=0, max=0;
for(k=0; k<120; k++)
{
if(a[k]>max)
{
result=k;
max=a[k];
count=1;
}
else if(max==a[k])
count++;
}
if(count==1)
{
printf("The jumping champion is %d\n", result);
}
else
{
printf("No jumping champion\n");
}
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
bool flag[10001];
int primes[10001],result[10001];
int cnt,s;
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
void value() {
//cout<<"p"<<N<<endl;
for (int i = 0; i < cnt; i++) {
s = 0;
for (int j = i; j < cnt; j++) {
s += primes[j];
if (s > 10001)
cout<<"s value"<<s<<endl;
continue;
result[s]++;
}
}
}
int main() {
int n;
sieve(10001);
value();
while (cin>>n and n>0) {
cout<<result[n]<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc,i,num,k,j, A,B,C,D,E,F,G,H,I,J;
cin>>tc;
while(tc--)
{
A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0;
cin>>num;
for(i=1;i<=num;i++)
{
int s=i;
for( k=1 ; ; k++)
{
int mod=s%10;
if(mod==0)
A++;
if(mod==1)
B++;
if(mod==2)
C++;
if(mod==3)
D++;
if(mod==4)
E++;
if(mod==5)
F++;
if(mod==6)
G++;
if(mod==7)
H++;
if(mod==8)
I++;
if(mod==9)
J++;
s/=10;
if(s==0) break;
}
}
cout<<A<<" "<<B<<" "<<C<<" "<<D<<" "<<E<<" "<<F<<" "<<G<<" "<<H<<" "<<I<<" "<<J<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
int n,i,score,sum,count;
cin>>n;
for(i=0;i<n;i++)
{
sum=0, count=0;
cin>>s;
for(int j=0;j<s.size();j++)
{
if(s[j]=='O')
{
count++;
sum+=count;
}
if(s[j]=='X')
{
count=0;
}
}
// sum+=count;
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)==1 && n)
{
if(n==561 || n==1105 || n==1729 || n==2465 || n==2821 ||
n==6601 || n==8911 || n==10585 || n==15841 ||
n==29341 || n==41041 ||n== 46657|| n== 52633|| n==62745 ||
n==63973 || n==75361
)
printf("The number %d is a Carmichael number.\n",n);
else printf("%d is normal.\n",n);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
double a0,an,a1,a,b,t,tc,n;
double c[3002];
int i;
cin>>t;
while(t--)
{
b=0;
cin>>n;
cin>>a0>>an;
if(n==0) printf("%0.2lf\n",an);
else{
for( i=0;i<n;i++)
{
cin>>c[i];
b+=((n-i)*c[i])*2;
}
a=((n*a0)+an);
a1=(a-b)/(n+1);
printf("%0.2lf\n",a1);
}
if(t) printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
long long int reverse(long long int n)
{
long long int sum=0,r;
while(n)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
return sum;
}
int main()
{
long long int t, sum, count;
int cse;
cin >> cse;
for (int i=0; i<cse; i++)
{
sum=0, count=0;
cin >> t;
while(reverse(t) != t)
{
count++;
t += reverse(t);
}
printf("%lld %lld\n",count,t);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int get_count (int n);
int main()
{
int tc,i,j=0,n;
cin>>tc;
while(tc--)
{
scanf("%d",&n);
printf("%d ",get_count(n));
char s[50];
sprintf(s, "%d" ,n);
sscanf(s, "%x" ,&n);
printf("%d\n",get_count(n));
}
return 0;
}
int get_count (int n)
{
int c=0;
while(n != 0)
{
if ( n & 1)
c++;
n=n >> 1;
}
return c;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
long int a,b,x,y;
while(cin >> a >> b)
{
if (a == 0 && b == 0) break;
long int count=0,c=0;
while( a > 0 || b > 0)
{
count = (a%10 + b%10 + count)/10;
a/= 10;
b /= 10;
if (count) c++;
}
if (c == 0) printf ("No carry operation.\n");
else if(c==1)
printf("%ld carry operation.\n",c);
else
printf("%ld carry operations.\n",c);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int a[502];
int main()
{
int i,j,t,n,sum;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int v = a[n / 2];
sum = 0;
for (int j = 0; j < n; j++) {
sum += abs(v - a[j]);
}
cout<<sum<<endl;
}
return 0;
}