by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc,cases=0,j,r;
char s[1000],c;
cin>>tc;
while(tc--)
{
scanf("\r");
gets(s);
int l=strlen(s);
printf("Case %d: ",++cases);
for(int i=0;i<l;i++)
{
r=0;
if(s[i]>='A'&&s[i]<='Z')
c=s[i];
else
{
while(s[i]>='0'&& s[i]<='9')
{
r=r*10+s[i]-'0';
i++;
}
i--;
for( j=0;j<r;j++)
printf("%c",c);
}
}
printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t = 0,i,n;
cin >> t;
while(t--)
{
int n = 0;
cin >> n;
n *= 567;
n /= 9;
n += 7492;
n *= 235;
n /= 47;
n-= 498;
n/=10;
n%=10;
printf("%d\n",abs(n));
}
return 0;
}
by Jesmin Akther | Jan 2, 2019 | Problem Solving, UVa
struct and union in C
These both declare same and uses are almost same;
just the difference when use
struct then need to declare with ‘struct’ keyword
struct student
{
int roll;
float age;
};
when use union then declare as
union student
{
int roll;
float age;
};
There is also a strong difference between struct and union
struct size measure by sum of all the used datatypes in struct;
like
struct student
{
int roll;
float age;
};
for this student struct datatype size is 6 bytes i.e ( 2 + 4);
union student
{
int roll;
float age;
};
where union size measure by the largest data size like in this example
student union data types size is 4 bytes.
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int p,b,h,w,price,i,a,j,s;
while(scanf("%d %d %d %d",&p,&b,&h,&w)==4)
{
int cost=15000000;
for(i=0;i<h;i++)
{
scanf("%d",&price);
for(j=0;j<w;j++)
{
scanf("%d",&a);
s=0;
if(a>=p)
{
s=price*p;
if(cost>s)
cost=s;
}
}
}
if(cost<=b)
cout<<cost<<endl;
else
cout<<"stay home"<<endl;
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <stdio.h>
int main ()
{
int problem1,prblm [20],required [20],tc = 0;
while ( scanf ("%d", &problem1)== 1 ) {
if ( problem1 < 0 )
return 0;
prblm [0] = problem1;
int i;
for ( i = 1; i < 13; i++ )
scanf ("%d", &prblm [i]);
for ( i = 0; i < 12; i++ )
scanf ("%d", &required [i]);
printf ("Case %d:\n", ++tc);
for ( i = 0; i < 12; i++ ) {
if ( problem1 >= required [i] ) {
problem1 -= required [i];
printf ("No problem! :D\n");
}
else
printf ("No problem. :(\n");
problem1 += prblm [i + 1];
}
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main ()
{
int p ,i, n ,l;
int c = 0;
while(cin>>n)
{
if(n<0)
{
break;
}
else
{
for(i=0;i<n;i++)
{
l=pow(2,i);
if(l>=n)
break;
}
}
printf("Case %d: %d\n",c+1,i);
c++;
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
bool flag[10000000];
long long int List[200000],primes[10000017];
int listSize,cnt,loc;
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+=2*i)
{
flag[j]=1;
}
}
}
return ;
}
void primeFactorize(long long int n,int loc)
{
listSize=0;
for(int i=0;i<loc;i++)
{
if(n%primes[i]==0)
{
while(n%primes[i]==0)
{
n/=primes[i];
List[listSize++]=primes[i];
}
}
}
if(n>1)
List[listSize++]=n;
return ;
}
int main()
{
long long int n;
sieve(10000000);
while(scanf("%lld",&n)==1)
{
loc=0;
if(n==0)
return 0;
else if(n<0)
n=(-1)*n;
for(int i=0;i<cnt;i++)
{
if(primes[i]<=sqrt(n))
loc++;
else
break;
}
primeFactorize(n,loc);
//cout<<"pos"<<pos<<endl;
if(listSize <= 1 || List[listSize-1]-List[0]==0)
printf("-1\n");
else
printf("%lld\n",List[listSize-1]);
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc, hour, mint;
cin>>tc;
while(tc--)
{
scanf("%d:%d", &hour, &mint);
hour= 11-hour + (mint == 0);
if(hour <= 0)
hour=hour+12;
if(mint != 0)
mint = 60-mint;
printf("%02d:%02d\n",hour,mint);
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int h1,m1,h2,m2;
while(cin>>h1>>m1>>h2>>m2)
{
if(h1==0 && m1==0 && h2==0 && m2==0) break;
h1*=60;
h1+=m1;
h2*=60;
h2+=m2;
cout<<abs(h2-h1)<<endl;
}
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int e,f,t,div,ate,val,c,rem;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&e,&f,&c);
ate=0;
val=e+f;
while(val>=c)
{
div=val/c;
ate+=div;
rem=val%c;
val=div+rem;
}
printf("%d\n",ate);
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <string.h>
#include <stdio.h>
char s1[1000],s2[1000],n1[1000],n2[1000];
int main()
{
char l,m,g,h;
int t,i,j,k,r;
scanf("%d%*c",&t);
while(t--)
{
gets(s1);
gets(s2);
l=strlen(s1);
m=strlen(s2);
if(l==m)
{
g=0,h=0;
for(k=0;k<l;k++)
{
if(s1[k]=='a'||s1[k]=='e'||s1[k]=='i'||s1[k]=='o'||s1[k]=='u')
continue;
else
n1[g]=s1[k];
g++;
}
n1[g]='\0';
for(r=0;r<m;r++)
{
if(s2[r]=='a'||s2[r]=='e'||s2[r]=='i'||s2[r]=='o'||s2[r]=='u')
continue;
else
n2[h]=s2[r];
h++;
}
n2[h]='\0';
if(strcmp(n1,n2)==0)
printf("Yes\n");
else printf("No\n");
}
else
printf("No\n");
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[10009];
float sq;
int k,len,num,i,j,temp;
cin>>num;
while(num--)
{
scanf("\r");
gets(s);
len=strlen(s);
sq=sqrt(len);
int p=(int)sq;
char ch[p][p];
if(p == sq)
{
int n=0;
for(i=0;i<p;i++)
{
for(j=0;j<p;j++)
{
ch[i][j]=s[n++];
//printf("%c",ch[j][i]);
}
}
for(i=0;i<p;i++)
{
for(j=0;j<p;j++)
{
printf("%c",ch[j][i]);
}
}
cout<<"\n";
}
else
{
cout<<"INVALID"<<endl;
}
//l=strlen(s);
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <stdio.h>
#include <string.h>
int main()
{
char s1[500],s2[500],s1s[500],s2s[500];
int t,i,j,k;
scanf("%d ",&t);
for(i=0;i<t;i++){
gets(s1);
gets(s2);
if(strcmp(s1,s2)==0)printf("Case %d: Yes\n",i+1);
else {
k=0;
for(j=0;j<strlen(s1);j++){
if(s1[j]!=' '){
s1s[k]=s1[j];
k++;
}
}
s1s[k]='\0';
k=0;
for(j=0;j<strlen(s2);j++){
if(s2s[j]!=' '){
s2s[k]=s2[j];
k++;
}
}
s2s[k]='\0';
if(strcmp(s1s,s2s)==0)printf("Case %d: Output Format Error\n",i+1);
else printf("Case %d: Wrong Answer\n",i+1);
}
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc,n,c,a[51],i;
cin>>tc;
for(int j=1;j<=tc;j++)
{
cin>>n;
int h=0;
int l=0;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n-1;i++)
{
if(a[i+1]>a[i])
{
h++;
}
else if(a[i+1]<a[i])
{
l++;
}
}
printf("Case %d: %d %d\n",j,h,l);
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t1,t2,f,a,ct1,ct2,ct3,sum,avr,c,t;
cin>>t;
for(c=0;c<t;c++)
{
sum=0;
cin>>t1>>t2>>f>>a>>ct1>>ct2>>ct3;
{
if(ct1<=ct2 && ct1<=ct3)
avr=(ct2+ct3)/2;
if(ct2<=ct1 && ct2<=ct3)
avr=(ct1+ct3)/2;
if(ct3<=ct1 && ct3<=ct2)
avr=(ct1+ct2)/2;
sum=t1+t2+f+a+avr;
if(sum>=90)
printf("Case %d: A\n",c+1);
else if(sum>=80)
printf("Case %d: B\n",c+1);
else if(sum>=70)
printf("Case %d: C\n",c+1);
else if(sum>=60)
printf("Case %d: D\n",c+1);
else if(sum<60)
printf("Case %d: F\n",c+1);
}
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int e,a;
while(cin>>a)
{
if(a==0) break;
e=0;
while(a>=3)
{
a=a-3;
e++;
a++;
}
if(a==2)
{
cout<<e+1<<endl;
}
else
cout<<e<<endl;
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,p,result,tc,i,j,c=0;
while(cin>>tc)
{
while(tc--)
{
cin>>n>>k>>p;
result=k+p;
while(result>n)
{
result-=n;
}
printf("Case %d: %d\n",c+1,result);
c++;
}
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, array[10], c, d, t;
while(cin>>array[0]>>array[1]>>array[2])
{
if(array[0]==0 and array[1]==0 and array[2]==0) break;
for (c = 0 ; c <= 2; c++) {
d = c;
while ( d > 0 && array[d] < array[d-1]) {
t = array[d];
array[d] = array[d-1];
array[d-1] = t;
d--;
}
}
int x=array[0];
int y=array[1];
int z=array[2];
if(pow(x,2) + pow(y,2)==pow(z,2))
{
printf("right\n");
}
else
printf("wrong\n");
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
char input[1050];
int main()
{
int i,j,l,rem,total;
while(1)
{
l=strlen(gets(input));
rem=0;
if(l==1 and input[0]=='0') break;
for(i=0;i<l;i++)
{
total=rem*10 + (input[i] - '0');
rem=total%17;
//these two eqn same rem=(rem*10 + (input[i] - '0'))%17;
}
if(rem==0) cout<<"1\n";
else
cout<<"0\n";
}
return 0;
}
by Jesmin Akther | Jan 1, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
int tc,n,p,q,b,i,j,a[30],sum,sr=1,egg,wt;
while(cin>>tc)
{
for(j=1;j<=tc;j++)
{
cin>>n>>p>>q;
for(i=0;i<n;i++)
{
cin>>a[i];
}
egg=0,wt=0;
for(i=0;i<n;i++)
{
if(egg<p and wt+a[i]<=q)
{
egg++;
//printf("he %d",egg);
wt+=a[i];
}
}
printf("Case %d: %d\n",sr++,egg);
}
}
return 0;
}