//11362
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
bool cmp(string a,string b)
{
if(a.size()>b.size())
return false;
for(size_t i=0;i<a.length();i++)
{
if(a[i]!=b[i])
return false;
}
return true;
}
int main()
{
int i,test,n;
string a[10100];
while(scanf("%d",&test)==1)
{
for(int k=0;k<test;k++)
{
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
bool flag=true;
for(i=0;i<n-1;i++)
{
if( cmp(a[i],a[i+1]) )
{
flag=false;
break;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}
}
Monday, June 11, 2012
UVA Solution for 10940
#include<stdio.h>
int main()
{
int x,n,s;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
x=1;
while(x<=n)
{
x=x*2;
s=x%n;
}
printf("%d\n",n-s);
}
}
/*
1. By multiplying x with 2, we are actually tracking
the cards after throwing and moving at the bottom.
2. By s = x%n and Result = n – s, we are getting the
card position and card number.
*/
int main()
{
int x,n,s;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
x=1;
while(x<=n)
{
x=x*2;
s=x%n;
}
printf("%d\n",n-s);
}
}
/*
1. By multiplying x with 2, we are actually tracking
the cards after throwing and moving at the bottom.
2. By s = x%n and Result = n – s, we are getting the
card position and card number.
*/
UVA Solution for 10905
#include<stdio.h>
#include<algorithm>
#include <vector>
#include <cstring>
#include <iostream>
#include <cctype>
#include <string.h>
using namespace std;
bool cmp(string x,string y)
{
string t1=x+y;
string t2=y+x;
if(t1>t2)
return true;
return false;
}
int main()
{
int test,i;
string a[60];
while(scanf("%d",&test)==1)
{
if(test==0)
break;
for(i=0;i<test;i++)
cin>>a[i];
sort(a,a+test,cmp);
for(i=0;i<test;i++)
cout<<a[i];
cout<<endl;
}
}
#include<algorithm>
#include <vector>
#include <cstring>
#include <iostream>
#include <cctype>
#include <string.h>
using namespace std;
bool cmp(string x,string y)
{
string t1=x+y;
string t2=y+x;
if(t1>t2)
return true;
return false;
}
int main()
{
int test,i;
string a[60];
while(scanf("%d",&test)==1)
{
if(test==0)
break;
for(i=0;i<test;i++)
cin>>a[i];
sort(a,a+test,cmp);
for(i=0;i<test;i++)
cout<<a[i];
cout<<endl;
}
}
UVA Solution for 10579
#include<stdio.h>
#define lim 5001
#define len 1050
int fbn[lim][len];
void fibonacci()
{
int i,j,k,sum;
fbn[0][0]=0;
fbn[1][0]=1;
fbn[2][0]=1;
for(i=3;i<lim;i++)
{
for(j=0;j<len;j++)
{
fbn[i][j]=fbn[i][j]+fbn[i-2][j]+fbn[i-1][j];
if(fbn[i][j]>=10)
{
fbn[i][j+1]=fbn[i][j+1]+fbn[i][j]/10;
fbn[i][j]=fbn[i][j]%10;
}
}
}
}
int main()
{
fibonacci();
int n,i,j,k,lenth;
while(scanf("%d",&n)==1)
{
for(i=len-1;i>0;i--)
{
if(fbn[n][i]!=0)break;
}
for(;i>=0;i--)printf("%d",fbn[n][i]);
printf("\n");
}
return 0;
}
#define lim 5001
#define len 1050
int fbn[lim][len];
void fibonacci()
{
int i,j,k,sum;
fbn[0][0]=0;
fbn[1][0]=1;
fbn[2][0]=1;
for(i=3;i<lim;i++)
{
for(j=0;j<len;j++)
{
fbn[i][j]=fbn[i][j]+fbn[i-2][j]+fbn[i-1][j];
if(fbn[i][j]>=10)
{
fbn[i][j+1]=fbn[i][j+1]+fbn[i][j]/10;
fbn[i][j]=fbn[i][j]%10;
}
}
}
}
int main()
{
fibonacci();
int n,i,j,k,lenth;
while(scanf("%d",&n)==1)
{
for(i=len-1;i>0;i--)
{
if(fbn[n][i]!=0)break;
}
for(;i>=0;i--)printf("%d",fbn[n][i]);
printf("\n");
}
return 0;
}
UVA Solution for 10491
#include<stdio.h>
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
double ncows,nshow,ncars,a,b,c,d;
double ans;
while(scanf("%lf%lf%lf",&ncows,&ncars,&nshow)==3)
{
ans=(1.0*(ncows*ncars+ncars*(ncars-1))/(ncows+ncars-nshow-1))/(ncows+ncars);
printf("%.5lf\n",ans);
}
}
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
double ncows,nshow,ncars,a,b,c,d;
double ans;
while(scanf("%lf%lf%lf",&ncows,&ncars,&nshow)==3)
{
ans=(1.0*(ncows*ncars+ncars*(ncars-1))/(ncows+ncars-nshow-1))/(ncows+ncars);
printf("%.5lf\n",ans);
}
}
UVA Solution for 10469
#include<stdio.h>
#include<stdlib.h>
int main()
{
long a,b;
while(scanf("%ld%ld",&a,&b)==2)
{
long c=a^b;
printf("%ld\n",c);
}
system("PAUSE");
}
/*
wrong
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned long a,b,c;
while(scanf("%uld%uld",&a,&b)==2)
{
c=a^b;
printf("%uld\n",c);
}
system("PAUSE");
}
*/
#include<stdlib.h>
int main()
{
long a,b;
while(scanf("%ld%ld",&a,&b)==2)
{
long c=a^b;
printf("%ld\n",c);
}
system("PAUSE");
}
/*
wrong
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned long a,b,c;
while(scanf("%uld%uld",&a,&b)==2)
{
c=a^b;
printf("%uld\n",c);
}
system("PAUSE");
}
*/
UVA Solution for 10220
#include<stdio.h>
#define max 1001
#define len 2600
int num[max][len];
void fact()
{
int i,j;
num[0][0]=num[1][0]=1;
for(i=2;i<max;i++)
for(j=0;j<len;j++)
{
num[i][j]+=num[i-1][j]*i;
if(num[i][j]>9)
{
num[i][j+1]+=num[i][j]/10;
num[i][j]%=10;
}
}
}
int main()
{
int n,i,sum;
fact();
while(scanf("%d",&n)==1)
{
sum=0;
for(i=0;i<len;i++)
sum+=num[n][i];
printf("%d\n",sum);
}
return 0;
}
#define max 1001
#define len 2600
int num[max][len];
void fact()
{
int i,j;
num[0][0]=num[1][0]=1;
for(i=2;i<max;i++)
for(j=0;j<len;j++)
{
num[i][j]+=num[i-1][j]*i;
if(num[i][j]>9)
{
num[i][j+1]+=num[i][j]/10;
num[i][j]%=10;
}
}
}
int main()
{
int n,i,sum;
fact();
while(scanf("%d",&n)==1)
{
sum=0;
for(i=0;i<len;i++)
sum+=num[n][i];
printf("%d\n",sum);
}
return 0;
}
UVA Solution for 10006
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
int a[20]={561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973};
while(scanf("%d",&n)==1)
{
if(n==0)
break;
if(n==a[0] || n==a[1] || n==a[2] ||n==a[3] ||n==a[4] ||n==a[5] ||n==a[6] ||n==a[7] ||n==a[8] ||n==a[9] ||n==a[10] ||n==a[11] ||n==a[12] ||n==a[13] ||n==a[14] )
printf("The number %d is a Carmichael number.\n",n);
else
printf("%d is normal.\n",n);
} }
#include<stdlib.h>
int main()
{
int n;
int a[20]={561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973};
while(scanf("%d",&n)==1)
{
if(n==0)
break;
if(n==a[0] || n==a[1] || n==a[2] ||n==a[3] ||n==a[4] ||n==a[5] ||n==a[6] ||n==a[7] ||n==a[8] ||n==a[9] ||n==a[10] ||n==a[11] ||n==a[12] ||n==a[13] ||n==a[14] )
printf("The number %d is a Carmichael number.\n",n);
else
printf("%d is normal.\n",n);
} }
UVA Solution for 623
#include<stdio.h>
#define max 1001
#define len 2600
int fact[max][len];
void calc()
{
int i,j,k;
fact[0][0]=fact[1][0]=1;
for(i=2;i<max;i++)
{
for(j=0;j<len;j++)
{
fact[i][j]+=fact[i-1][j]*i;
if(fact[i][j]>9)
{
fact[i][j+1]+=fact[i][j]/10;
fact[i][j]%=10;
}
}
}
}
int main()
{
long i,j,n;
calc();
while(scanf("%ld",&n)==1)
{
printf("%ld!\n",n);
for(i=len-1;i>0;i--)
if(fact[n][i]!=0)
break;
for(;i>=0;i--)
printf("%d",fact[n][i]);
printf("\n");
}
return 0;
}
#define max 1001
#define len 2600
int fact[max][len];
void calc()
{
int i,j,k;
fact[0][0]=fact[1][0]=1;
for(i=2;i<max;i++)
{
for(j=0;j<len;j++)
{
fact[i][j]+=fact[i-1][j]*i;
if(fact[i][j]>9)
{
fact[i][j+1]+=fact[i][j]/10;
fact[i][j]%=10;
}
}
}
}
int main()
{
long i,j,n;
calc();
while(scanf("%ld",&n)==1)
{
printf("%ld!\n",n);
for(i=len-1;i>0;i--)
if(fact[n][i]!=0)
break;
for(;i>=0;i--)
printf("%d",fact[n][i]);
printf("\n");
}
return 0;
}
UVA Solution for 495
#include<stdio.h>
#define lim 5001
#define len 1050
int fbn[lim][len];
void fibonacci()
{
int i,j,k,sum;
fbn[0][0]=0;
fbn[1][0]=1;
fbn[2][0]=1;
for(i=3;i<lim;i++)
{
for(j=0;j<len;j++)
{
fbn[i][j]+=fbn[i-2][j]+fbn[i-1][j];
if(fbn[i][j]>=10)
{
fbn[i][j+1]+=fbn[i][j]/10;
fbn[i][j]%=10;
}
}
}
}
int main()
{
fibonacci();
int n,i,j,k,lenth;
while(scanf("%d",&n)==1)
{
for(i=len-1;i>0;i--)
{
if(fbn[n][i]!=0)break;
}
printf("The Fibonacci number for %d is ",n);
for(;i>=0;i--)printf("%d",fbn[n][i]);
printf("\n");
}
return 0;
}
#define lim 5001
#define len 1050
int fbn[lim][len];
void fibonacci()
{
int i,j,k,sum;
fbn[0][0]=0;
fbn[1][0]=1;
fbn[2][0]=1;
for(i=3;i<lim;i++)
{
for(j=0;j<len;j++)
{
fbn[i][j]+=fbn[i-2][j]+fbn[i-1][j];
if(fbn[i][j]>=10)
{
fbn[i][j+1]+=fbn[i][j]/10;
fbn[i][j]%=10;
}
}
}
}
int main()
{
fibonacci();
int n,i,j,k,lenth;
while(scanf("%d",&n)==1)
{
for(i=len-1;i>0;i--)
{
if(fbn[n][i]!=0)break;
}
printf("The Fibonacci number for %d is ",n);
for(;i>=0;i--)printf("%d",fbn[n][i]);
printf("\n");
}
return 0;
}
UVA Solution for 488
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int c, a, f;
cin >> c;
for (int i = 0; i < c; i++)
{
cin >> a >> f;
for (int j = 0; j < f; j++)
{
if (j > 0 || i > 0)
cout << endl;
for (int k = 0; k < a; k++)
{
for (int l = 0; l < k+1; l++)
{
cout << (k%a) + 1;
}
cout << endl;
}
for (int k = 0; k < a-1; k++)
{
for (int l = 0; l < a-1-k; l++)
{
cout << a-1-k;
}
cout << endl;
}
}
}
return 0;
}
#include <string>
using namespace std;
int main ()
{
int c, a, f;
cin >> c;
for (int i = 0; i < c; i++)
{
cin >> a >> f;
for (int j = 0; j < f; j++)
{
if (j > 0 || i > 0)
cout << endl;
for (int k = 0; k < a; k++)
{
for (int l = 0; l < k+1; l++)
{
cout << (k%a) + 1;
}
cout << endl;
}
for (int k = 0; k < a-1; k++)
{
for (int l = 0; l < a-1-k; l++)
{
cout << a-1-k;
}
cout << endl;
}
}
}
return 0;
}
UVA Solution for 11703
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
#define N 1000000
using namespace std;
int x[1000020];
void calc()
{
x[0]=1;
for(int i=1;i<=N;i++)
{
x[i]=x[(int)floor(i-sqrt(i))]+x[(int)floor(log(i))]+x[(int)floor(i*sin(i)*sin(i))];
x[i]%=N;
}
}
int main()
{
calc();
int a,b,c,d,i;
while(scanf("%d",&i)==1)
{
if(i==-1)
break;
printf("%d\n",x[i]);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
#define N 1000000
using namespace std;
int x[1000020];
void calc()
{
x[0]=1;
for(int i=1;i<=N;i++)
{
x[i]=x[(int)floor(i-sqrt(i))]+x[(int)floor(log(i))]+x[(int)floor(i*sin(i)*sin(i))];
x[i]%=N;
}
}
int main()
{
calc();
int a,b,c,d,i;
while(scanf("%d",&i)==1)
{
if(i==-1)
break;
printf("%d\n",x[i]);
}
}
UVA Solution for 11494
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
int i,j,v,u,x;
while(scanf("%d%d%d%d",&i,&j,&v,&u)==4)
{
if(i==0 && j==0 && v==0 && u==0)
break;
if(i==v && j==u)
x=0;
else if(i==v || j==u || abs(i-v)==abs(j-u))
x=1;
else
x=2;
printf("%d\n",x);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
int i,j,v,u,x;
while(scanf("%d%d%d%d",&i,&j,&v,&u)==4)
{
if(i==0 && j==0 && v==0 && u==0)
break;
if(i==v && j==u)
x=0;
else if(i==v || j==u || abs(i-v)==abs(j-u))
x=1;
else
x=2;
printf("%d\n",x);
}
}
UVA Solution for 10656
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
int a,b[1001],c;
while(scanf("%d",&a)==1)
{
if(a==0)
break;
int space =0;
for(c=0;c<a;c++)
{
scanf("%d",&b[c]);
}
for(c=0;c<a;c++)
{
if(b[c]>0)
{
if(space)
printf(" ");
space=1;
printf("%d",b[c]);
}
}
if(space==0)
printf("0");
printf("\n");
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
int a,b[1001],c;
while(scanf("%d",&a)==1)
{
if(a==0)
break;
int space =0;
for(c=0;c<a;c++)
{
scanf("%d",&b[c]);
}
for(c=0;c<a;c++)
{
if(b[c]>0)
{
if(space)
printf(" ");
space=1;
printf("%d",b[c]);
}
}
if(space==0)
printf("0");
printf("\n");
}
}
UVA Solution for 11877
//11877
//rank 484
#include<stdio.h>
int main()
{
long int cola,half,total;
while(scanf("%ld",&cola)==1)
{
if(cola==0)
break;
printf("%ld\n",cola>>1);
}
}
//rank 484
#include<stdio.h>
int main()
{
long int cola,half,total;
while(scanf("%ld",&cola)==1)
{
if(cola==0)
break;
printf("%ld\n",cola>>1);
}
}
UVA Solution for 11877
//11877
//rank 481
#include<stdio.h>
int main()
{
long int cola,half,total;
while(scanf("%ld",&cola)==1)
{
if(cola==0)
break;
half=cola/2;
printf("%ld\n",half);
}
}
//rank 481
#include<stdio.h>
int main()
{
long int cola,half,total;
while(scanf("%ld",&cola)==1)
{
if(cola==0)
break;
half=cola/2;
printf("%ld\n",half);
}
}
UVA Solution for 11417
//11417
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int g;
int i,j,n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
g=0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
g+=gcd(i,j);
}
printf("%d\n",g);
}
}
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int g;
int i,j,n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
g=0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
g+=gcd(i,j);
}
printf("%d\n",g);
}
}
UVA Solution for 11364
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
int i,j,test,k,n,start,end;
while(scanf("%d",&test)==1)
{
for(i=0;i<test;i++)
{
vector<int>v;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%d",&k);
v.push_back(k);
}
sort(v.begin(),v.end());
start=v[0];
end=v[n-1];
printf("%d\n",(end-start)*2);
}
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
int i,j,test,k,n,start,end;
while(scanf("%d",&test)==1)
{
for(i=0;i<test;i++)
{
vector<int>v;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%d",&k);
v.push_back(k);
}
sort(v.begin(),v.end());
start=v[0];
end=v[n-1];
printf("%d\n",(end-start)*2);
}
}
}
UVA Solution for 10286
//10286
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
#define f 1.0673956817111818692592637626711;//from felix_halim
int main()
{
double v,vel;
while(scanf("%lf",&v)==1)
{
vel=v*f;
printf("%.10lf\n",vel);
}
}
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
#define f 1.0673956817111818692592637626711;//from felix_halim
int main()
{
double v,vel;
while(scanf("%lf",&v)==1)
{
vel=v*f;
printf("%.10lf\n",vel);
}
}
UVA Solution for 138
//138
//0.012_time
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int R[20] = {
6,8,
35,49,
204,288,
1189,1681,
6930,9800,
40391,57121,
235416,332928,
1372105,1940449,
7997214,11309768,
46611179,65918161
}; felix_halim
int main()
{
int i;
for(i=0;i<20;i=i+2)
{
printf("%10d%10d\n",R[i],R[i+1]);
}
system("PAUSE");
}
//0.012_time
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int R[20] = {
6,8,
35,49,
204,288,
1189,1681,
6930,9800,
40391,57121,
235416,332928,
1372105,1940449,
7997214,11309768,
46611179,65918161
}; felix_halim
int main()
{
int i;
for(i=0;i<20;i=i+2)
{
printf("%10d%10d\n",R[i],R[i+1]);
}
system("PAUSE");
}
UVA Solution for 138
//138
//time 0.424
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
long long temp,r,res,i;
int counter=0;
for(i=2;counter<10;i++)
{
temp=1+8*i*i;
r=sqrt(temp);
if(r*r==temp)
{
int test=(r+1)/2-1;
cout.width(10);
cout<<i;
cout.width(10);
cout<<test<<endl;
counter++;
}
}
return 0;
}
//time 0.424
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
long long temp,r,res,i;
int counter=0;
for(i=2;counter<10;i++)
{
temp=1+8*i*i;
r=sqrt(temp);
if(r*r==temp)
{
int test=(r+1)/2-1;
cout.width(10);
cout<<i;
cout.width(10);
cout<<test<<endl;
counter++;
}
}
return 0;
}
UVA Solution for 11636
//reproduction
//rank
//previous rank 1365
#include <stdio.h>
#include <math.h>
int main ()
{
int n;
int cases = 0;
while ( scanf ("%d", &n) && n >= 0 ) {
printf ("Case %d: %0.lf\n", ++cases, ceil (log (n) / log (2)));
}
return 0;
}
//rank
//previous rank 1365
#include <stdio.h>
#include <math.h>
int main ()
{
int n;
int cases = 0;
while ( scanf ("%d", &n) && n >= 0 ) {
printf ("Case %d: %0.lf\n", ++cases, ceil (log (n) / log (2)));
}
return 0;
}
UVA Solution for 11614
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
long test,n,i;
double x;
scanf("%ld",&test);
while(test--)
{
scanf("%ld",&n);
double x=( ( sqrt(1+8*n) )-1 )/2.0;
/*
double x= sqrt(1+8*n) ;
x=x-1;
x=x/2;*/
int long h=floor(x);
printf("%ld\n",h);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
long test,n,i;
double x;
scanf("%ld",&test);
while(test--)
{
scanf("%ld",&n);
double x=( ( sqrt(1+8*n) )-1 )/2.0;
/*
double x= sqrt(1+8*n) ;
x=x-1;
x=x/2;*/
int long h=floor(x);
printf("%ld\n",h);
}
}
UVA Solution for 11614
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
long test,n,i;
double x;
scanf("%ld",&test);
while(test--)
{
scanf("%ld",&n);
double x=( ( sqrt(1+8*n) )-1 )/2.0;
/*
double x= sqrt(1+8*n) ;
x=x-1;
x=x/2;*/
x=floor(x);
printf("%.0lf\n",x);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
long test,n,i;
double x;
scanf("%ld",&test);
while(test--)
{
scanf("%ld",&n);
double x=( ( sqrt(1+8*n) )-1 )/2.0;
/*
double x= sqrt(1+8*n) ;
x=x-1;
x=x/2;*/
x=floor(x);
printf("%.0lf\n",x);
}
}
UVA Solution for 10852
#include <iostream>
#include<stdio.h>
using namespace std;
int is_prime (int x)
{
for (int i = 2; i * i <= x; i++)
{
if (x % i == 0)
return 0;
}
return 1;
}
int main ()
{
int n, test;
cin >> test;
while (test--)
{
cin >> n;
int k = n / 2 + 1;
while (1)
{
if (is_prime (k))
{
printf("%d\n", k);
break;
}
k++;
}
}
return 0;
}
#include<stdio.h>
using namespace std;
int is_prime (int x)
{
for (int i = 2; i * i <= x; i++)
{
if (x % i == 0)
return 0;
}
return 1;
}
int main ()
{
int n, test;
cin >> test;
while (test--)
{
cin >> n;
int k = n / 2 + 1;
while (1)
{
if (is_prime (k))
{
printf("%d\n", k);
break;
}
k++;
}
}
return 0;
}
UVA Solution for 11389
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
#include<string.h>
#define max 150
using namespace std;
int main()
{
int n,d,r,i,j,cost,temp;
while(scanf("%d%d%d",&n,&d,&r)==3)
{
if(n==0 && d==0 && r==0)
break;
int mor[max];
int eve[max];
for(i=0;i<n;i++)
scanf("%d",&mor[i]);
sort(mor,mor+n);
for(i=0;i<n;i++)
scanf("%d",&eve[i]);
sort(eve,eve+n);
cost=0;
for(i=0;i<n;i++)
{
temp=mor[i]+eve[n-i-1];
if(temp>d)
cost=cost+(temp-d);
}
printf("%d\n",r*cost);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
#include<string.h>
#define max 150
using namespace std;
int main()
{
int n,d,r,i,j,cost,temp;
while(scanf("%d%d%d",&n,&d,&r)==3)
{
if(n==0 && d==0 && r==0)
break;
int mor[max];
int eve[max];
for(i=0;i<n;i++)
scanf("%d",&mor[i]);
sort(mor,mor+n);
for(i=0;i<n;i++)
scanf("%d",&eve[i]);
sort(eve,eve+n);
cost=0;
for(i=0;i<n;i++)
{
temp=mor[i]+eve[n-i-1];
if(temp>d)
cost=cost+(temp-d);
}
printf("%d\n",r*cost);
}
}
UVA Solution for 10852
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
#define max 10000
using namespace std;
int prime[1230]={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 ,1019 ,1021 ,1031 ,1033 ,1039 ,1049 ,1051 ,1061 ,1063 ,1069 ,1087 ,1091 ,1093 ,1097 ,1103 ,1109 ,1117 ,1123 ,1129 ,1151 ,1153 ,1163 ,1171
,1181 ,1187 ,1193 ,1201 ,1213 ,1217 ,1223 ,1229 ,1231 ,1237 ,1249 ,1259 ,1277 ,1279 ,
1283 ,1289 ,1291 ,1297 ,1301 ,1303 ,1307 ,1319 ,1321 ,1327 ,1361 ,1367 ,1373 ,
1381 ,1399 ,1409 ,1423 ,1427 ,1429 ,1433 ,1439 ,1447 ,1451 ,1453 ,1459 ,1471,
1481 ,1483 ,1487 ,1489 ,1493 ,1499 ,1511 ,1523 ,1531 ,1543 ,1549 ,1553 ,1559 ,
1567 ,1571 ,1579 ,1583 ,1597 ,1601 ,1607 ,1609 ,1613 ,1619 ,1621 ,1627 ,1637 ,
1657 ,1663 ,1667 ,1669 ,1693 ,1697 ,1699 ,1709 ,1721 ,1723 ,1733 ,1741 ,1747 ,
1753,1759 ,1777 ,1783 ,1787 ,1789 ,1801 ,1811 ,1823 ,1831 ,1847 ,1861 ,1867 ,1871 ,
1873 ,1877 ,1879 ,1889 ,1901 ,1907 ,1913 ,1931 ,1933 ,1949 ,1951 ,1973 ,1979 ,1987 ,1993 ,1997 ,1999 ,2003 ,2011 ,2017 ,2027 ,2029 ,2039 ,2053 ,2063 ,2069 ,2081,
2083 ,2087 ,2089 ,2099 ,2111 ,2113 ,2129 ,2131 ,2137 ,2141 ,2143 ,2153 ,2161 ,2179 ,
2203 ,2207 ,2213 ,2221 ,2237 ,2239 ,2243 ,2251 ,2267 ,2269 ,2273 ,2281 ,2287 ,
2293 ,2297 ,2309 ,2311 ,2333 ,2339 ,2341 ,2347 ,2351 ,2357 ,2371 ,2377 ,2381,
2383 ,2389 ,2393 ,2399 ,2411 ,2417 ,2423 ,2437 ,2441 ,2447 ,2459 ,2467 ,2473 ,2477 ,
2503 ,2521 ,2531 ,2539 ,2543 ,2549 ,2551 ,2557 ,2579 ,2591 ,2593 ,2609 ,2617 ,
2621 ,2633 ,2647 ,2657 ,2659 ,2663 ,2671 ,2677 ,2683 ,2687 ,2689 ,2693 ,2699,2707 ,
2711 ,2713 ,2719 ,2729 ,2731 ,2741 ,2749 ,2753 ,2767 ,2777 ,2789 ,2791 ,2797 ,
2801 ,2803 ,2819 ,2833 ,2837 ,2843 ,2851 ,2857 ,2861 ,2879 ,2887 ,2897 ,2903 ,
2909 ,2917 ,2927 ,2939 ,2953 ,2957 ,2963 ,2969 ,2971 ,2999 ,3001 ,3011 ,3019,
3023 ,3037 ,3041 ,3049 ,3061 ,3067 ,3079 ,3083 ,3089 ,3109 ,3119 ,3121 ,3137 ,
3163 ,3167 ,3169 ,3181 ,3187 ,3191 ,3203 ,3209 ,3217 ,3221 ,3229 ,3251 ,3253 ,
3257 ,3259 ,3271 ,3299 ,3301 ,3307 ,3313 ,3319 ,3323 ,3329 ,3331 ,3343 ,3347 ,3359,
3361 ,3371 ,3373 ,3389 ,3391 ,3407 ,3413 ,3433 ,3449 ,3457 ,3461 ,3463 ,3467 ,3469 ,
3491 ,3499 ,3511 ,3517 ,3527 ,3529 ,3533 ,3539 ,3541 ,3547 ,3557 ,3559 ,3571 ,
3581 ,3583 ,3593 ,3607 ,3613 ,3617 ,3623 ,3631 ,3637 ,3643 ,3659 ,3671 ,3673,
3677 ,3691 ,3697 ,3701 ,3709 ,3719 ,3727 ,3733 ,3739 ,3761 ,3767 ,3769 ,3779 ,3793 ,
3797 ,3803 ,3821 ,3823 ,3833 ,3847 ,3851 ,3853 ,3863 ,3877 ,3881 ,3889 ,3907 ,
3911 ,3917 ,3919 ,3923 ,3929 ,3931 ,3943 ,3947 ,3967 ,3989 ,4001 ,4003 ,4007,
4013 ,4019 ,4021 ,4027 ,4049 ,4051 ,4057 ,4073 ,4079 ,4091 ,4093 ,4099 ,4111 ,4127 ,
4129 ,4133 ,4139 ,4153 ,4157 ,4159 ,4177 ,4201 ,4211 ,4217 ,4219 ,4229 ,4231 ,
4241 ,4243 ,4253 ,4259 ,4261 ,4271 ,4273 ,4283 ,4289 ,4297 ,4327 ,4337 ,4339,
4349 ,4357 ,4363 ,4373 ,4391 ,4397 ,4409 ,4421 ,4423 ,4441 ,4447 ,4451 ,4457 ,4463 ,
4481 ,4483 ,4493 ,4507 ,4513 ,4517 ,4519 ,4523 ,4547 ,4549 ,4561 ,4567 ,4583 ,
4591 ,4597 ,4603 ,4621 ,4637 ,4639 ,4643 ,4649 ,4651 ,4657 ,4663 ,4673 ,4679,
4691 ,4703 ,4721 ,4723 ,4729 ,4733 ,4751 ,4759 ,4783 ,4787 ,4789 ,4793 ,4799 ,4801 ,
4813 ,4817 ,4831 ,4861 ,4871 ,4877 ,4889 ,4903 ,4909 ,4919 ,4931 ,4933 ,4937 ,
4943 ,4951 ,4957 ,4967 ,4969 ,4973 ,4987 ,4993 ,4999 ,5003 ,5009 ,5011 ,5021,
5023 ,5039 ,5051 ,5059 ,5077 ,5081 ,5087 ,5099 ,5101 ,5107 ,5113 ,5119 ,5147 ,5153 ,
5167 ,5171 ,5179 ,5189 ,5197 ,5209 ,5227 ,5231 ,5233 ,5237 ,5261 ,5273 ,5279 ,
5281 ,5297 ,5303 ,5309 ,5323 ,5333 ,5347 ,5351 ,5381 ,5387 ,5393 ,5399 ,5407
,5413 ,5417 ,5419 ,5431 ,5437 ,5441 ,5443 ,5449 ,5471 ,5477 ,5479 ,5483 ,5501 ,5503 ,
5507 ,5519 ,5521 ,5527 ,5531 ,5557 ,5563 ,5569 ,5573 ,5581 ,5591 ,5623 ,5639 ,
5641 ,5647 ,5651 ,5653 ,5657 ,5659 ,5669 ,5683 ,5689 ,5693 ,5701 ,5711 ,5717,
5737 ,5741 ,5743 ,5749 ,5779 ,5783 ,5791 ,5801 ,5807 ,5813 ,5821 ,5827 ,5839 ,5843 ,
5849 ,5851 ,5857 ,5861 ,5867 ,5869 ,5879 ,5881 ,5897 ,5903 ,5923 ,5927 ,
5939 ,5953 ,5981 ,5987 ,6007 ,6011 ,6029 ,6037 ,6043 ,6047 ,6053 ,6067 ,6073 ,6079,
6089 ,6091 ,6101 ,6113 ,6121 ,6131 ,6133 ,6143 ,6151 ,6163 ,6173 ,6197 ,6199 ,6203 ,
6211 ,6217 ,6221 ,6229 ,6247 ,6257 ,6263 ,6269 ,6271 ,6277 ,6287 ,6299 ,6301 ,
6311 ,6317 ,6323 ,6329 ,6337 ,6343 ,6353 ,6359 ,6361 ,6367 ,6373 ,6379 ,6389,
6397 ,6421 ,6427 ,6449 ,6451 ,6469 ,6473 ,6481 ,6491 ,6521 ,6529 ,6547 ,6551 ,6553 ,
6563 ,6569 ,6571 ,6577 ,6581 ,6599 ,6607 ,6619 ,6637 ,6653 ,6659 ,6661 ,6673 ,
6679 ,6689 ,6691 ,6701 ,6703 ,6709 ,6719 ,6733 ,6737 ,6761 ,6763 ,6779 ,6781,
6791 ,6793 ,6803 ,6823 ,6827 ,6829 ,6833 ,6841 ,6857 ,6863 ,6869 ,6871 ,6883 ,6899 ,
6907 ,6911 ,6917 ,6947 ,6949 ,6959 ,6961 ,6967 ,6971 ,6977 ,6983 ,6991 ,6997 ,
7001 ,7013 ,7019 ,7027 ,7039 ,7043 ,7057 ,7069 ,7079 ,7103 ,7109 ,7121 ,7127,
7129 ,7151 ,7159 ,7177 ,7187 ,7193 ,7207 ,7211 ,7213 ,7219 ,7229 ,7237 ,7243 ,7247 ,
7253 ,7283 ,7297 ,7307 ,7309 ,7321 ,7331 ,7333 ,7349 ,7351 ,7369 ,7393 ,7411 ,
7417 ,7433 ,7451 ,7457 ,7459 ,7477 ,7481 ,7487 ,7489 ,7499 ,7507 ,7517 ,7523,
7529 ,7537 ,7541 ,7547 ,7549 ,7559 ,7561 ,7573 ,7577 ,7583 ,7589 ,7591 ,7603 ,7607 ,
7621 ,7639 ,7643 ,7649 ,7669 ,7673 ,7681 ,7687 ,7691 ,7699 ,7703 ,7717 ,7723 ,
7727 ,7741 ,7753 ,7757 ,7759 ,7789 ,7793 ,7817 ,7823 ,7829 ,7841 ,7853 ,7867,
7873 ,7877 ,7879 ,7883 ,7901 ,7907 ,7919 ,7927 ,7933 ,7937 ,7949 ,7951 ,7963 ,7993 ,
8009 ,8011 ,8017 ,8039 ,8053 ,8059 ,8069 ,8081 ,8087 ,8089 ,8093 ,8101 ,8111 ,
8117 ,8123 ,8147 ,8161 ,8167 ,8171 ,8179 ,8191 ,8209 ,8219 ,8221 ,8231 ,8233,
8237 ,8243 ,8263 ,8269 ,8273 ,8287 ,8291 ,8293 ,8297 ,8311 ,8317 ,8329 ,8353 ,8363 ,
8369 ,8377 ,8387 ,8389 ,8419 ,8423 ,8429 ,8431 ,8443 ,8447 ,8461 ,8467 ,8501 ,
8513 ,8521 ,8527 ,8537 ,8539 ,8543 ,8563 ,8573 ,8581 ,8597 ,8599 ,8609 ,8623,
8627 ,8629 ,8641 ,8647 ,8663 ,8669 ,8677 ,8681 ,8689 ,8693 ,8699 ,8707 ,8713 ,8719 ,
8731 ,8737 ,8741 ,8747 ,8753 ,8761 ,8779 ,8783 ,8803 ,8807 ,8819 ,8821 ,8831 ,
8837 ,8839 ,8849 ,8861 ,8863 ,8867 ,8887 ,8893 ,8923 ,8929 ,8933 ,8941 ,8951,
8963 ,8969 ,8971 ,8999 ,9001 ,9007 ,9011 ,9013 ,9029 ,9041 ,9043 ,9049 ,9059 ,9067 ,
9091 ,9103 ,9109 ,9127 ,9133 ,9137 ,9151 ,9157 ,9161 ,9173 ,9181 ,9187 ,9199 ,
9203 ,9209 ,9221 ,9227 ,9239 ,9241 ,9257 ,9277 ,9281 ,9283 ,9293 ,9311 ,9319,
9323 ,9337 ,9341 ,9343 ,9349 ,9371 ,9377 ,9391 ,9397 ,9403 ,9413 ,9419 ,9421 ,9431 ,
9433 ,9437 ,9439 ,9461 ,9463 ,9467 ,9473 ,9479 ,9491 ,9497 ,9511 ,9521 ,9533 ,
9539 ,9547 ,9551 ,9587 ,9601 ,9613 ,9619 ,9623 ,9629 ,9631 ,9643 ,9649 ,9661,
9677 ,9679 ,9689 ,9697 ,9719 ,9721 ,9733 ,9739 ,9743 ,9749 ,9767 ,9769 ,9781 ,9787 ,
9791 ,9803 ,9811 ,9817 ,9829 ,9833 ,9839 ,9851 ,9857 ,9859 ,9871 ,9883 ,9887 ,
9901 ,9907 ,9923 ,9929 ,9931 ,9941 ,9949 ,9967 ,9973};
//cout<<prime[1228];==9973
int main()
{
long test,n,i;
double x;
scanf("%d",&test);
while(test--)
{
scanf("%d",&n);
for(i=0;i<1229;i++)
{
int m=n/2+1;
if(prime[i]>=m)
{
printf("%d\n",prime[i]);
break;
}
}
}
system("PAUSE");
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
#define max 10000
using namespace std;
int prime[1230]={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 ,1019 ,1021 ,1031 ,1033 ,1039 ,1049 ,1051 ,1061 ,1063 ,1069 ,1087 ,1091 ,1093 ,1097 ,1103 ,1109 ,1117 ,1123 ,1129 ,1151 ,1153 ,1163 ,1171
,1181 ,1187 ,1193 ,1201 ,1213 ,1217 ,1223 ,1229 ,1231 ,1237 ,1249 ,1259 ,1277 ,1279 ,
1283 ,1289 ,1291 ,1297 ,1301 ,1303 ,1307 ,1319 ,1321 ,1327 ,1361 ,1367 ,1373 ,
1381 ,1399 ,1409 ,1423 ,1427 ,1429 ,1433 ,1439 ,1447 ,1451 ,1453 ,1459 ,1471,
1481 ,1483 ,1487 ,1489 ,1493 ,1499 ,1511 ,1523 ,1531 ,1543 ,1549 ,1553 ,1559 ,
1567 ,1571 ,1579 ,1583 ,1597 ,1601 ,1607 ,1609 ,1613 ,1619 ,1621 ,1627 ,1637 ,
1657 ,1663 ,1667 ,1669 ,1693 ,1697 ,1699 ,1709 ,1721 ,1723 ,1733 ,1741 ,1747 ,
1753,1759 ,1777 ,1783 ,1787 ,1789 ,1801 ,1811 ,1823 ,1831 ,1847 ,1861 ,1867 ,1871 ,
1873 ,1877 ,1879 ,1889 ,1901 ,1907 ,1913 ,1931 ,1933 ,1949 ,1951 ,1973 ,1979 ,1987 ,1993 ,1997 ,1999 ,2003 ,2011 ,2017 ,2027 ,2029 ,2039 ,2053 ,2063 ,2069 ,2081,
2083 ,2087 ,2089 ,2099 ,2111 ,2113 ,2129 ,2131 ,2137 ,2141 ,2143 ,2153 ,2161 ,2179 ,
2203 ,2207 ,2213 ,2221 ,2237 ,2239 ,2243 ,2251 ,2267 ,2269 ,2273 ,2281 ,2287 ,
2293 ,2297 ,2309 ,2311 ,2333 ,2339 ,2341 ,2347 ,2351 ,2357 ,2371 ,2377 ,2381,
2383 ,2389 ,2393 ,2399 ,2411 ,2417 ,2423 ,2437 ,2441 ,2447 ,2459 ,2467 ,2473 ,2477 ,
2503 ,2521 ,2531 ,2539 ,2543 ,2549 ,2551 ,2557 ,2579 ,2591 ,2593 ,2609 ,2617 ,
2621 ,2633 ,2647 ,2657 ,2659 ,2663 ,2671 ,2677 ,2683 ,2687 ,2689 ,2693 ,2699,2707 ,
2711 ,2713 ,2719 ,2729 ,2731 ,2741 ,2749 ,2753 ,2767 ,2777 ,2789 ,2791 ,2797 ,
2801 ,2803 ,2819 ,2833 ,2837 ,2843 ,2851 ,2857 ,2861 ,2879 ,2887 ,2897 ,2903 ,
2909 ,2917 ,2927 ,2939 ,2953 ,2957 ,2963 ,2969 ,2971 ,2999 ,3001 ,3011 ,3019,
3023 ,3037 ,3041 ,3049 ,3061 ,3067 ,3079 ,3083 ,3089 ,3109 ,3119 ,3121 ,3137 ,
3163 ,3167 ,3169 ,3181 ,3187 ,3191 ,3203 ,3209 ,3217 ,3221 ,3229 ,3251 ,3253 ,
3257 ,3259 ,3271 ,3299 ,3301 ,3307 ,3313 ,3319 ,3323 ,3329 ,3331 ,3343 ,3347 ,3359,
3361 ,3371 ,3373 ,3389 ,3391 ,3407 ,3413 ,3433 ,3449 ,3457 ,3461 ,3463 ,3467 ,3469 ,
3491 ,3499 ,3511 ,3517 ,3527 ,3529 ,3533 ,3539 ,3541 ,3547 ,3557 ,3559 ,3571 ,
3581 ,3583 ,3593 ,3607 ,3613 ,3617 ,3623 ,3631 ,3637 ,3643 ,3659 ,3671 ,3673,
3677 ,3691 ,3697 ,3701 ,3709 ,3719 ,3727 ,3733 ,3739 ,3761 ,3767 ,3769 ,3779 ,3793 ,
3797 ,3803 ,3821 ,3823 ,3833 ,3847 ,3851 ,3853 ,3863 ,3877 ,3881 ,3889 ,3907 ,
3911 ,3917 ,3919 ,3923 ,3929 ,3931 ,3943 ,3947 ,3967 ,3989 ,4001 ,4003 ,4007,
4013 ,4019 ,4021 ,4027 ,4049 ,4051 ,4057 ,4073 ,4079 ,4091 ,4093 ,4099 ,4111 ,4127 ,
4129 ,4133 ,4139 ,4153 ,4157 ,4159 ,4177 ,4201 ,4211 ,4217 ,4219 ,4229 ,4231 ,
4241 ,4243 ,4253 ,4259 ,4261 ,4271 ,4273 ,4283 ,4289 ,4297 ,4327 ,4337 ,4339,
4349 ,4357 ,4363 ,4373 ,4391 ,4397 ,4409 ,4421 ,4423 ,4441 ,4447 ,4451 ,4457 ,4463 ,
4481 ,4483 ,4493 ,4507 ,4513 ,4517 ,4519 ,4523 ,4547 ,4549 ,4561 ,4567 ,4583 ,
4591 ,4597 ,4603 ,4621 ,4637 ,4639 ,4643 ,4649 ,4651 ,4657 ,4663 ,4673 ,4679,
4691 ,4703 ,4721 ,4723 ,4729 ,4733 ,4751 ,4759 ,4783 ,4787 ,4789 ,4793 ,4799 ,4801 ,
4813 ,4817 ,4831 ,4861 ,4871 ,4877 ,4889 ,4903 ,4909 ,4919 ,4931 ,4933 ,4937 ,
4943 ,4951 ,4957 ,4967 ,4969 ,4973 ,4987 ,4993 ,4999 ,5003 ,5009 ,5011 ,5021,
5023 ,5039 ,5051 ,5059 ,5077 ,5081 ,5087 ,5099 ,5101 ,5107 ,5113 ,5119 ,5147 ,5153 ,
5167 ,5171 ,5179 ,5189 ,5197 ,5209 ,5227 ,5231 ,5233 ,5237 ,5261 ,5273 ,5279 ,
5281 ,5297 ,5303 ,5309 ,5323 ,5333 ,5347 ,5351 ,5381 ,5387 ,5393 ,5399 ,5407
,5413 ,5417 ,5419 ,5431 ,5437 ,5441 ,5443 ,5449 ,5471 ,5477 ,5479 ,5483 ,5501 ,5503 ,
5507 ,5519 ,5521 ,5527 ,5531 ,5557 ,5563 ,5569 ,5573 ,5581 ,5591 ,5623 ,5639 ,
5641 ,5647 ,5651 ,5653 ,5657 ,5659 ,5669 ,5683 ,5689 ,5693 ,5701 ,5711 ,5717,
5737 ,5741 ,5743 ,5749 ,5779 ,5783 ,5791 ,5801 ,5807 ,5813 ,5821 ,5827 ,5839 ,5843 ,
5849 ,5851 ,5857 ,5861 ,5867 ,5869 ,5879 ,5881 ,5897 ,5903 ,5923 ,5927 ,
5939 ,5953 ,5981 ,5987 ,6007 ,6011 ,6029 ,6037 ,6043 ,6047 ,6053 ,6067 ,6073 ,6079,
6089 ,6091 ,6101 ,6113 ,6121 ,6131 ,6133 ,6143 ,6151 ,6163 ,6173 ,6197 ,6199 ,6203 ,
6211 ,6217 ,6221 ,6229 ,6247 ,6257 ,6263 ,6269 ,6271 ,6277 ,6287 ,6299 ,6301 ,
6311 ,6317 ,6323 ,6329 ,6337 ,6343 ,6353 ,6359 ,6361 ,6367 ,6373 ,6379 ,6389,
6397 ,6421 ,6427 ,6449 ,6451 ,6469 ,6473 ,6481 ,6491 ,6521 ,6529 ,6547 ,6551 ,6553 ,
6563 ,6569 ,6571 ,6577 ,6581 ,6599 ,6607 ,6619 ,6637 ,6653 ,6659 ,6661 ,6673 ,
6679 ,6689 ,6691 ,6701 ,6703 ,6709 ,6719 ,6733 ,6737 ,6761 ,6763 ,6779 ,6781,
6791 ,6793 ,6803 ,6823 ,6827 ,6829 ,6833 ,6841 ,6857 ,6863 ,6869 ,6871 ,6883 ,6899 ,
6907 ,6911 ,6917 ,6947 ,6949 ,6959 ,6961 ,6967 ,6971 ,6977 ,6983 ,6991 ,6997 ,
7001 ,7013 ,7019 ,7027 ,7039 ,7043 ,7057 ,7069 ,7079 ,7103 ,7109 ,7121 ,7127,
7129 ,7151 ,7159 ,7177 ,7187 ,7193 ,7207 ,7211 ,7213 ,7219 ,7229 ,7237 ,7243 ,7247 ,
7253 ,7283 ,7297 ,7307 ,7309 ,7321 ,7331 ,7333 ,7349 ,7351 ,7369 ,7393 ,7411 ,
7417 ,7433 ,7451 ,7457 ,7459 ,7477 ,7481 ,7487 ,7489 ,7499 ,7507 ,7517 ,7523,
7529 ,7537 ,7541 ,7547 ,7549 ,7559 ,7561 ,7573 ,7577 ,7583 ,7589 ,7591 ,7603 ,7607 ,
7621 ,7639 ,7643 ,7649 ,7669 ,7673 ,7681 ,7687 ,7691 ,7699 ,7703 ,7717 ,7723 ,
7727 ,7741 ,7753 ,7757 ,7759 ,7789 ,7793 ,7817 ,7823 ,7829 ,7841 ,7853 ,7867,
7873 ,7877 ,7879 ,7883 ,7901 ,7907 ,7919 ,7927 ,7933 ,7937 ,7949 ,7951 ,7963 ,7993 ,
8009 ,8011 ,8017 ,8039 ,8053 ,8059 ,8069 ,8081 ,8087 ,8089 ,8093 ,8101 ,8111 ,
8117 ,8123 ,8147 ,8161 ,8167 ,8171 ,8179 ,8191 ,8209 ,8219 ,8221 ,8231 ,8233,
8237 ,8243 ,8263 ,8269 ,8273 ,8287 ,8291 ,8293 ,8297 ,8311 ,8317 ,8329 ,8353 ,8363 ,
8369 ,8377 ,8387 ,8389 ,8419 ,8423 ,8429 ,8431 ,8443 ,8447 ,8461 ,8467 ,8501 ,
8513 ,8521 ,8527 ,8537 ,8539 ,8543 ,8563 ,8573 ,8581 ,8597 ,8599 ,8609 ,8623,
8627 ,8629 ,8641 ,8647 ,8663 ,8669 ,8677 ,8681 ,8689 ,8693 ,8699 ,8707 ,8713 ,8719 ,
8731 ,8737 ,8741 ,8747 ,8753 ,8761 ,8779 ,8783 ,8803 ,8807 ,8819 ,8821 ,8831 ,
8837 ,8839 ,8849 ,8861 ,8863 ,8867 ,8887 ,8893 ,8923 ,8929 ,8933 ,8941 ,8951,
8963 ,8969 ,8971 ,8999 ,9001 ,9007 ,9011 ,9013 ,9029 ,9041 ,9043 ,9049 ,9059 ,9067 ,
9091 ,9103 ,9109 ,9127 ,9133 ,9137 ,9151 ,9157 ,9161 ,9173 ,9181 ,9187 ,9199 ,
9203 ,9209 ,9221 ,9227 ,9239 ,9241 ,9257 ,9277 ,9281 ,9283 ,9293 ,9311 ,9319,
9323 ,9337 ,9341 ,9343 ,9349 ,9371 ,9377 ,9391 ,9397 ,9403 ,9413 ,9419 ,9421 ,9431 ,
9433 ,9437 ,9439 ,9461 ,9463 ,9467 ,9473 ,9479 ,9491 ,9497 ,9511 ,9521 ,9533 ,
9539 ,9547 ,9551 ,9587 ,9601 ,9613 ,9619 ,9623 ,9629 ,9631 ,9643 ,9649 ,9661,
9677 ,9679 ,9689 ,9697 ,9719 ,9721 ,9733 ,9739 ,9743 ,9749 ,9767 ,9769 ,9781 ,9787 ,
9791 ,9803 ,9811 ,9817 ,9829 ,9833 ,9839 ,9851 ,9857 ,9859 ,9871 ,9883 ,9887 ,
9901 ,9907 ,9923 ,9929 ,9931 ,9941 ,9949 ,9967 ,9973};
//cout<<prime[1228];==9973
int main()
{
long test,n,i;
double x;
scanf("%d",&test);
while(test--)
{
scanf("%d",&n);
for(i=0;i<1229;i++)
{
int m=n/2+1;
if(prime[i]>=m)
{
printf("%d\n",prime[i]);
break;
}
}
}
system("PAUSE");
}
UVA Solution for 10473
//10473
#include<iostream>
#include<sstream>
#include<map>
#include<stdio.h>
using namespace std;
int main()
{
string buff;
int n;
while(cin>>buff)
{
if(buff[0]=='-')
break;
if( buff.size()>1 && buff[1]=='x')
{
sscanf(buff.c_str(),"%X",&n);
printf("%d\n",n);
}
else
{
sscanf(buff.c_str(),"%d",&n);
printf("0x%X\n",n);
}
}
}
#include<iostream>
#include<sstream>
#include<map>
#include<stdio.h>
using namespace std;
int main()
{
string buff;
int n;
while(cin>>buff)
{
if(buff[0]=='-')
break;
if( buff.size()>1 && buff[1]=='x')
{
sscanf(buff.c_str(),"%X",&n);
printf("%d\n",n);
}
else
{
sscanf(buff.c_str(),"%d",&n);
printf("0x%X\n",n);
}
}
}
UVA Solution for 10282
#include<iostream>
#include<sstream>
#include<map>
using namespace std;
int main()
{
map<string,string>M;
string a,b,buff;
while(getline(cin,buff),buff.size())
{
stringstream ss;
ss<<buff;
ss>>a>>b;
M[b]=a;
}
while(cin>>buff)
{
cout<<(M.count(buff) ?M[buff] : "eh")<<endl;
}
}
#include<sstream>
#include<map>
using namespace std;
int main()
{
map<string,string>M;
string a,b,buff;
while(getline(cin,buff),buff.size())
{
stringstream ss;
ss<<buff;
ss>>a>>b;
M[b]=a;
}
while(cin>>buff)
{
cout<<(M.count(buff) ?M[buff] : "eh")<<endl;
}
}
UVA Solution for 834
//834 – Continued Fractions
#include<iostream>
#include<sstream>
#include<map>
using namespace std;
int main()
{
int i,num,den;
while(cin>>num>>den)
{
cout<<"["<<num/den;
num=num%den;
swap(num,den);
for(i=0;i<num;i++)
{
if(i==0)
cout<<";";
if(i>0)
cout<<",";
cout<<num/den;
num=num%den;
swap(num,den);
}
cout<<"]"<<endl;
}
}
#include<iostream>
#include<sstream>
#include<map>
using namespace std;
int main()
{
int i,num,den;
while(cin>>num>>den)
{
cout<<"["<<num/den;
num=num%den;
swap(num,den);
for(i=0;i<num;i++)
{
if(i==0)
cout<<";";
if(i>0)
cout<<",";
cout<<num/den;
num=num%den;
swap(num,den);
}
cout<<"]"<<endl;
}
}
UVA Solution for 408
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int gcd(int a,int b)
{
while (b > 0)
{
a %= b;
swap (a, b);
}
return a;
}
int main()
{
int step,mode,a;
while(scanf("%d%d",&step,&mode)==2)
{
if(gcd(step,mode)==1)
printf("%10d%10d Good Choice\n\n",step,mode);
else
printf("%10d%10d Bad Choice\n\n",step,mode);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int gcd(int a,int b)
{
while (b > 0)
{
a %= b;
swap (a, b);
}
return a;
}
int main()
{
int step,mode,a;
while(scanf("%d%d",&step,&mode)==2)
{
if(gcd(step,mode)==1)
printf("%10d%10d Good Choice\n\n",step,mode);
else
printf("%10d%10d Bad Choice\n\n",step,mode);
}
}
UVA Solution for 408
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int step,mode,a;
while(scanf("%d%d",&step,&mode)==2)
{
a=gcd(step,mode);
if(a==1)
printf("%10d%10d Good Choice\n\n",step,mode);
else
printf("%10d%10d Bad Choice\n\n",step,mode);
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int step,mode,a;
while(scanf("%d%d",&step,&mode)==2)
{
a=gcd(step,mode);
if(a==1)
printf("%10d%10d Good Choice\n\n",step,mode);
else
printf("%10d%10d Bad Choice\n\n",step,mode);
}
}
UVA Solution for 271
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
#include<string.h>
using namespace std;
int main()
{
char a[10000];
int i,j,n,k,len;
while(gets(a))
{
n=0;
len=strlen(a);
for(i=len-1;i>=0;i--)
{
if(a[i]>111 && a[i]<123)
n++;
else if (a[i]=='C' || a[i]=='D' || a[i]=='E' || a[i]=='I')
{
if(n>=2)
n--;
else
{n=0;
break;}
}
else if(a[i]=='N')
{
if(n<1)
{
n=0;
break;
}
else
n=n;
}
}
if(n==1)
printf("YES\n");
else
printf("NO\n");
}
}
/*
This problem its not that much easy as it looks. For this problem I am giving here an Algorithm, afterwards I will explain it.
n = 0 // a variable containing total sentence, initialized as ZERO.
bank[1000] // here the given line will be stored
len = length of [bank]
for i = len - 1 down to 0 {
if bank[i] == any character between p through z
n = n+1
else if bank[i] == any character from C,D,E,I
if n > = 2
n = n - 1
else
n = 0
break
else if bank[i] == character N
if n < 1
n = 0
break
else
n = n // no change in 'n'
}
After completing the FOR loop.....
if n == 1
Print YES
else
Print NO
Now I am describing how does this algorithm work.
1. Any character from p to z is a correct sentence. So, when we get any of them we just increase the total sentence (n).
2. Two correct sentences and any one of C,D,I,E make a correct sentence. But this time at first our sentence number decrease two.
n = n -2
But with C,D,I,E it makes a new sentence. So,
n = n + 1
So, finally we get,
n = n - 2 + 1
n = n - 1
3. One correct sentence and N make a new sentence. Here also at first total sentence decrease one but then it increase again one. As a result there is no change in 'n'.
4. If we get less than two sentence before C,D,E & I, we just break the loop with assigning 0 at n. Finally it will work as flag. You may notice that we do not break the loop if we get more than two correct sentence. This is because to make with [C...I] we need two sentence and the extras are might be for some other parts. If not then we can track it later. But we can not consider less then two.
5. Same explanation goes for N also.
6. But...finally we must get one and only one correct sentence to tell that its is correct. If we don't get n = 1, then we can surely say that its not a correct sentence.
*/
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
#include<string.h>
using namespace std;
int main()
{
char a[10000];
int i,j,n,k,len;
while(gets(a))
{
n=0;
len=strlen(a);
for(i=len-1;i>=0;i--)
{
if(a[i]>111 && a[i]<123)
n++;
else if (a[i]=='C' || a[i]=='D' || a[i]=='E' || a[i]=='I')
{
if(n>=2)
n--;
else
{n=0;
break;}
}
else if(a[i]=='N')
{
if(n<1)
{
n=0;
break;
}
else
n=n;
}
}
if(n==1)
printf("YES\n");
else
printf("NO\n");
}
}
/*
This problem its not that much easy as it looks. For this problem I am giving here an Algorithm, afterwards I will explain it.
n = 0 // a variable containing total sentence, initialized as ZERO.
bank[1000] // here the given line will be stored
len = length of [bank]
for i = len - 1 down to 0 {
if bank[i] == any character between p through z
n = n+1
else if bank[i] == any character from C,D,E,I
if n > = 2
n = n - 1
else
n = 0
break
else if bank[i] == character N
if n < 1
n = 0
break
else
n = n // no change in 'n'
}
After completing the FOR loop.....
if n == 1
Print YES
else
Print NO
Now I am describing how does this algorithm work.
1. Any character from p to z is a correct sentence. So, when we get any of them we just increase the total sentence (n).
2. Two correct sentences and any one of C,D,I,E make a correct sentence. But this time at first our sentence number decrease two.
n = n -2
But with C,D,I,E it makes a new sentence. So,
n = n + 1
So, finally we get,
n = n - 2 + 1
n = n - 1
3. One correct sentence and N make a new sentence. Here also at first total sentence decrease one but then it increase again one. As a result there is no change in 'n'.
4. If we get less than two sentence before C,D,E & I, we just break the loop with assigning 0 at n. Finally it will work as flag. You may notice that we do not break the loop if we get more than two correct sentence. This is because to make with [C...I] we need two sentence and the extras are might be for some other parts. If not then we can track it later. But we can not consider less then two.
5. Same explanation goes for N also.
6. But...finally we must get one and only one correct sentence to tell that its is correct. If we don't get n = 1, then we can surely say that its not a correct sentence.
*/
UVA Solution for 146
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
char code[100];
while(scanf("%s",&code)==1)
{
if(code[0]=='#')
break;
int len=strlen(code);
if(next_permutation(code,code+len))
printf("%s\n",code);
else
printf("No Successor\n");
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
char code[100];
while(scanf("%s",&code)==1)
{
if(code[0]=='#')
break;
int len=strlen(code);
if(next_permutation(code,code+len))
printf("%s\n",code);
else
printf("No Successor\n");
}
}
UVA Solution for 146
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
string code;
while(cin>>code,code!="#")
{
cout<< (!next_permutation(code.begin(),code.end())?"No Successor" :code)<<endl;
}
}
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
string code;
while(cin>>code,code!="#")
{
cout<< (!next_permutation(code.begin(),code.end())?"No Successor" :code)<<endl;
}
}
11777
//11777
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int i,test,j;
char ch;
int Term1,Term2,Final,Attendance,Class_Test1,Class_Test2,Class_Test3,low,avg,sum;
while(scanf("%d",&test)==1)
{
for(i=1;i<=test;i++)
{
//cin>>Term1,Term2,Final,Attendance,Class_Test1,Class_Test2,Class_Test3;
scanf("%d%d%d%d%d%d%d",&Term1,&Term2,&Final,&Attendance,&Class_Test1,&Class_Test2,&Class_Test3);
/* low=0;
if(Class_Test1<low)
low=Class_Test1;
if(Class_Test2<low)
low=Class_Test2;
if(Class_Test3<low)
low=Class_Test3;
*/
vector<int>v;
v.push_back(Class_Test1);
v.push_back(Class_Test2);
v.push_back(Class_Test3);
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
avg=(v[0]+v[1])/2;
sum=Term1 + Term2 + Final+ Attendance+avg;
/// cout<<sum;
if(sum>=90)
printf("Case %d: A\n",i);
else if(sum>=80 && sum<90)
printf("Case %d: B\n",i);
else if(sum>=70 && sum<80)
printf("Case %d: C\n",i);
else if(sum>=60 && sum<70)
printf("Case %d: D\n",i);
else if (sum<60)
printf("Case %d: F\n",i);
}
}
}
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int i,test,j;
char ch;
int Term1,Term2,Final,Attendance,Class_Test1,Class_Test2,Class_Test3,low,avg,sum;
while(scanf("%d",&test)==1)
{
for(i=1;i<=test;i++)
{
//cin>>Term1,Term2,Final,Attendance,Class_Test1,Class_Test2,Class_Test3;
scanf("%d%d%d%d%d%d%d",&Term1,&Term2,&Final,&Attendance,&Class_Test1,&Class_Test2,&Class_Test3);
/* low=0;
if(Class_Test1<low)
low=Class_Test1;
if(Class_Test2<low)
low=Class_Test2;
if(Class_Test3<low)
low=Class_Test3;
*/
vector<int>v;
v.push_back(Class_Test1);
v.push_back(Class_Test2);
v.push_back(Class_Test3);
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
avg=(v[0]+v[1])/2;
sum=Term1 + Term2 + Final+ Attendance+avg;
/// cout<<sum;
if(sum>=90)
printf("Case %d: A\n",i);
else if(sum>=80 && sum<90)
printf("Case %d: B\n",i);
else if(sum>=70 && sum<80)
printf("Case %d: C\n",i);
else if(sum>=60 && sum<70)
printf("Case %d: D\n",i);
else if (sum<60)
printf("Case %d: F\n",i);
}
}
}
UVA Solution for 11597
//11597
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n,i=1;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
printf("Case %d: %d\n",i,n/2); //like 11550
i++;
}
}
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n,i=1;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
printf("Case %d: %d\n",i,n/2); //like 11550
i++;
}
}
UVA Solution for 10693
//10693
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
int n,i,l,f;
double v,velocity;
while(scanf("%d%d",&l,&f)==2)
{
if(l==0 && f==0)
break;
v=sqrt(l*f*2.0);
velocity=(v*3600)/(2*l);
printf("%.8lf %.8lf\n",v,velocity);
}
}
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctype.h>
using namespace std;
int main()
{
int n,i,l,f;
double v,velocity;
while(scanf("%d%d",&l,&f)==2)
{
if(l==0 && f==0)
break;
v=sqrt(l*f*2.0);
velocity=(v*3600)/(2*l);
printf("%.8lf %.8lf\n",v,velocity);
}
}
UVA Solution for 11805
#include <cstdlib>
#include <iostream>
#include<stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
int n,k,p,tst,t;
while(scanf("%d",&tst)==1)
{
for(t=1;t<=tst;t++)
{
scanf("%d%d%d",&n,&k,&p);
printf("Case %d: %d\n",t,((k-1+p)%n)+1 );
}
}
}
#include <iostream>
#include<stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
int n,k,p,tst,t;
while(scanf("%d",&tst)==1)
{
for(t=1;t<=tst;t++)
{
scanf("%d%d%d",&n,&k,&p);
printf("Case %d: %d\n",t,((k-1+p)%n)+1 );
}
}
}
UVA Solution for 10281
#include<stdio.h>
int main()
{
long i,j,k,len=0,hour,min,sec,v1,speed=0;
double total_distance=0,last_time=0;
char ch;
while(scanf("%c",&ch)==1)
{
if(ch>='0' && ch<='9')
{
switch(len)
{
case 0:
hour=(ch-48)*10;
break;
case 1:
hour=hour+ch-48;
break;
case 2:
min=(ch-48)*10;
break;
case 3:
min=min+ch-48;
break;
case 4:
sec=(ch-48)*10;
break;
case 5:
sec=sec+ch-48;
break;
case 6:
v1=ch-48;
break;
default:
v1=v1*10+ch-48;
}
len++;
}
else if(ch=='\n')
{
total_distance+=speed*(3600*hour+60*min+sec-last_time)/3600.0;
last_time=3600*hour+60*min+sec;
if(len==6)
printf("%02ld:%02ld:%02ld %.2lf km\n",hour,min,sec,total_distance);
else
speed=v1;
len=0;
}
}
return 0;
}
int main()
{
long i,j,k,len=0,hour,min,sec,v1,speed=0;
double total_distance=0,last_time=0;
char ch;
while(scanf("%c",&ch)==1)
{
if(ch>='0' && ch<='9')
{
switch(len)
{
case 0:
hour=(ch-48)*10;
break;
case 1:
hour=hour+ch-48;
break;
case 2:
min=(ch-48)*10;
break;
case 3:
min=min+ch-48;
break;
case 4:
sec=(ch-48)*10;
break;
case 5:
sec=sec+ch-48;
break;
case 6:
v1=ch-48;
break;
default:
v1=v1*10+ch-48;
}
len++;
}
else if(ch=='\n')
{
total_distance+=speed*(3600*hour+60*min+sec-last_time)/3600.0;
last_time=3600*hour+60*min+sec;
if(len==6)
printf("%02ld:%02ld:%02ld %.2lf km\n",hour,min,sec,total_distance);
else
speed=v1;
len=0;
}
}
return 0;
}
UVA Solution for 10276
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
int a,b,ts;
while(scanf("%d",&ts)==1)
{
for(b=0;b<ts;b++)
{
scanf("%d",&a);
printf("%d\n",((a*++a)>>1)-1);
}
}
}
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
int a,b,ts;
while(scanf("%d",&ts)==1)
{
for(b=0;b<ts;b++)
{
scanf("%d",&a);
printf("%d\n",((a*++a)>>1)-1);
}
}
}
UVA Solution for 11455
#include<stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long a,b,c,d,t,test,i,j,key,sum;
vector<long> x(4);
while(scanf("%ld",&test)==1)
{
for(t=0;t<test;t++)
{
for(i=0;i<4;i++)
scanf("%ld",&x[i]);
sort(x.begin(), x.end());
// printf("%ld %ld %ld %ld ",a,b,c,d);
//
if(x[0]==x[3])
printf("square\n");
else if(x[0]==x[1] && x[2]==x[3])
printf("rectangle\n");
// else if(a<sum && b<sum && c<sum &&d<sum )
else if(x[3]<(x[0]+x[1]+x[2]))
printf("quadrangle\n");
else
printf("banana\n");
}
}
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long a,b,c,d,t,test,i,j,key,sum;
vector<long> x(4);
while(scanf("%ld",&test)==1)
{
for(t=0;t<test;t++)
{
for(i=0;i<4;i++)
scanf("%ld",&x[i]);
sort(x.begin(), x.end());
// printf("%ld %ld %ld %ld ",a,b,c,d);
//
if(x[0]==x[3])
printf("square\n");
else if(x[0]==x[1] && x[2]==x[3])
printf("rectangle\n");
// else if(a<sum && b<sum && c<sum &&d<sum )
else if(x[3]<(x[0]+x[1]+x[2]))
printf("quadrangle\n");
else
printf("banana\n");
}
}
}
UVA Solution for 11556
//11556
#include<math.h>
#include<stdio.h>
int main()
{
double n,b,i,a,temp;
while(scanf("%lf%lf",&n,&b)==2)
{
temp=(pow(2,(b+1)) )-1;
if(n>=b)
printf("yes\n");
else
printf("no\n");
}
}
#include<math.h>
#include<stdio.h>
int main()
{
double n,b,i,a,temp;
while(scanf("%lf%lf",&n,&b)==2)
{
temp=(pow(2,(b+1)) )-1;
if(n>=b)
printf("yes\n");
else
printf("no\n");
}
}
UVA Solution for 11556
//11556
#include<math.h>
#include<stdio.h>
int main()
{
long n,b,i,a,temp;
while(scanf("%ld%ld",&n,&b)==2)
{
temp=(pow(2,(b+1)) )-1;
if(n>=b)
printf("yes\n");
else
printf("no\n");
}
}
#include<math.h>
#include<stdio.h>
int main()
{
long n,b,i,a,temp;
while(scanf("%ld%ld",&n,&b)==2)
{
temp=(pow(2,(b+1)) )-1;
if(n>=b)
printf("yes\n");
else
printf("no\n");
}
}
UVA Solution for 10082
#include<stdio.h>
#include<string.h>
#define max 1000
int main()
{
char ch[max];
int i,len;
while(gets(ch))
{
len=strlen(ch);
for(i=0;i<len;i++)
{
if(ch[i]=='/')
printf(".");
else if(ch[i]=='.')
printf("\,");
else if(ch[i]==',')
printf("M");
else if(ch[i]=='M')
printf("N");
else if(ch[i]=='N')
printf("B");
else if(ch[i]=='B')
printf("V");
else if(ch[i]=='V')
printf("C");
else if(ch[i]=='C')
printf("X");
else if(ch[i]=='X')
printf("Z");
else if(ch[i]=='Z')
printf("Z");
else if(ch[i]==';')
printf("L");
else if(ch[i]=='L')
printf("K");
else if(ch[i]=='K')
printf("J");
else if(ch[i]=='J')
printf("H");
else if(ch[i]=='H')
printf("G");
else if(ch[i]=='G')
printf("F");
else if(ch[i]=='F')
printf("D");
else if(ch[i]=='D')
printf("S");
else if(ch[i]=='S')
printf("A");
else if(ch[i]=='A')
printf("A");
else if(ch[i]=='\\')
printf("]");
else if(ch[i]==']')
printf("[");
else if(ch[i]=='[')
printf("P");
else if(ch[i]=='P')
printf("O");
else if(ch[i]=='O')
printf("I");
else if(ch[i]=='I')
printf("U");
else if(ch[i]=='U')
printf("Y");
else if(ch[i]=='Y')
printf("T");
else if(ch[i]=='T')
printf("R");
else if(ch[i]=='R')
printf("E");
else if(ch[i]=='E')
printf("W");
else if(ch[i]=='W')
printf("Q");
else if(ch[i]=='Q')
printf("Q");
else if(ch[i]=='=')
printf("-");
else if(ch[i]=='-')
printf("0");
else if(ch[i]=='0')
printf("9");
else if(ch[i]=='9')
printf("8");
else if(ch[i]=='8')
printf("7");
else if(ch[i]=='7')
printf("6");
else if(ch[i]=='6')
printf("5");
else if(ch[i]=='5')
printf("4");
else if(ch[i]=='4')
printf("3");
else if(ch[i]=='3')
printf("2");
else if(ch[i]=='2')
printf("1");
////
else if(ch[i]=='1')
printf("1");
//////////////
// else if(ch[i]=='`')
// printf("`");
///////////////////
else if(ch[i]=='\'')
printf(";");
else if(ch[i]==' ')
printf(" ");
}
printf("\n");
}
}
#include<string.h>
#define max 1000
int main()
{
char ch[max];
int i,len;
while(gets(ch))
{
len=strlen(ch);
for(i=0;i<len;i++)
{
if(ch[i]=='/')
printf(".");
else if(ch[i]=='.')
printf("\,");
else if(ch[i]==',')
printf("M");
else if(ch[i]=='M')
printf("N");
else if(ch[i]=='N')
printf("B");
else if(ch[i]=='B')
printf("V");
else if(ch[i]=='V')
printf("C");
else if(ch[i]=='C')
printf("X");
else if(ch[i]=='X')
printf("Z");
else if(ch[i]=='Z')
printf("Z");
else if(ch[i]==';')
printf("L");
else if(ch[i]=='L')
printf("K");
else if(ch[i]=='K')
printf("J");
else if(ch[i]=='J')
printf("H");
else if(ch[i]=='H')
printf("G");
else if(ch[i]=='G')
printf("F");
else if(ch[i]=='F')
printf("D");
else if(ch[i]=='D')
printf("S");
else if(ch[i]=='S')
printf("A");
else if(ch[i]=='A')
printf("A");
else if(ch[i]=='\\')
printf("]");
else if(ch[i]==']')
printf("[");
else if(ch[i]=='[')
printf("P");
else if(ch[i]=='P')
printf("O");
else if(ch[i]=='O')
printf("I");
else if(ch[i]=='I')
printf("U");
else if(ch[i]=='U')
printf("Y");
else if(ch[i]=='Y')
printf("T");
else if(ch[i]=='T')
printf("R");
else if(ch[i]=='R')
printf("E");
else if(ch[i]=='E')
printf("W");
else if(ch[i]=='W')
printf("Q");
else if(ch[i]=='Q')
printf("Q");
else if(ch[i]=='=')
printf("-");
else if(ch[i]=='-')
printf("0");
else if(ch[i]=='0')
printf("9");
else if(ch[i]=='9')
printf("8");
else if(ch[i]=='8')
printf("7");
else if(ch[i]=='7')
printf("6");
else if(ch[i]=='6')
printf("5");
else if(ch[i]=='5')
printf("4");
else if(ch[i]=='4')
printf("3");
else if(ch[i]=='3')
printf("2");
else if(ch[i]=='2')
printf("1");
////
else if(ch[i]=='1')
printf("1");
//////////////
// else if(ch[i]=='`')
// printf("`");
///////////////////
else if(ch[i]=='\'')
printf(";");
else if(ch[i]==' ')
printf(" ");
}
printf("\n");
}
}
UVA Solution for 10365
//10365
#include<stdio.h>
int main()
{
long a,test,b,n,min,i,j,k;
while(scanf("%ld",&test)==1)
{
for(a=0;a<test;a++)
{
scanf("%ld",&n);
min=1000000000;
for (i=1; i*i*i<=n; i++)
{
for (j=i; i*j*j<=n; j++)
{
if(n%(i*j))
continue;
k=n/(i*j);
if(2*(i*j+i*k+j*k)<min)
min=2*(i*j+i*k+j*k);
}
}
printf("%ld\n",min);
}
}
}
#include<stdio.h>
int main()
{
long a,test,b,n,min,i,j,k;
while(scanf("%ld",&test)==1)
{
for(a=0;a<test;a++)
{
scanf("%ld",&n);
min=1000000000;
for (i=1; i*i*i<=n; i++)
{
for (j=i; i*j*j<=n; j++)
{
if(n%(i*j))
continue;
k=n/(i*j);
if(2*(i*j+i*k+j*k)<min)
min=2*(i*j+i*k+j*k);
}
}
printf("%ld\n",min);
}
}
}
UVA Solution for 10212
#include<stdio.h>
int main()
{
long n,m,i,temp,digit,two;
while(2==scanf("%ld%ld",&n,&m))
{
two=0;
digit=1;
for (i=n-m+1; i<=n; i++)
{
temp=i;
while(temp%2==0)
{
temp=(temp>>1);
two++;
}
while(temp%5==0)
{
temp=temp/5;
two--;
}
digit=(digit*temp)%10;
}
for (i=1; i<=two; i++)
digit=(digit<<1)%10;
if (two<0)
digit=5;
printf("%ld\n",digit);
}
return 0;
}
int main()
{
long n,m,i,temp,digit,two;
while(2==scanf("%ld%ld",&n,&m))
{
two=0;
digit=1;
for (i=n-m+1; i<=n; i++)
{
temp=i;
while(temp%2==0)
{
temp=(temp>>1);
two++;
}
while(temp%5==0)
{
temp=temp/5;
two--;
}
digit=(digit*temp)%10;
}
for (i=1; i<=two; i++)
digit=(digit<<1)%10;
if (two<0)
digit=5;
printf("%ld\n",digit);
}
return 0;
}
UVA Solution for 10101
//10101
#include<stdio.h>
#include<string.h>
int main()
{
char st[17],strev[17];
int i,j,temp,a,n,len,t=1,num;
while(scanf("%s",strev)==1)
{
for (len=0;strev[len]!='\0'; len++);
// len=strlen(strev);
for(i=0;i<len;i++)
st[len-i-1]=strev[i];
len--;
printf("%4d.",t);
t++;
if(len==14)
printf(" %d kuti",st[14]-48);
if(len>=12)
{
num=st[12]-48;
if(len>=13)
num=num+10*(st[13]-48);
if(num>0)
printf(" %d lakh",num);
}
if(len>=10)
{
num=st[10]-48;
if(len>=11)
num=num+10*(st[11]-48);
//num=num*10+st[11]-48;
if(num>0)
printf(" %d hajar",num);
}
if(len>=9)
{
num=st[9]-48;
if(num>0)
printf(" %d shata",num);
}
if(len>=7)
{
num=st[7]-48;
if(len>=8)
num=num+10*(st[8]-48);
// num=num*10+st[8]-48;
if(num>0)
printf(" %d",num);
printf(" kuti");
// printf(" %d kuti",num);
}
if(len>=5)
{
num=st[5]-48;
if(len>=6)
num=num+10*(st[6]-48);
// num=num*10+st[6]-48;
if(num>0)
printf(" %d lakh",num);
}
if(len>=3)
{
num=st[3]-48;
if(len>=4)
num=num+10*(st[4]-48);
//num=num*10+st[4]-48;
if(num>0)
printf(" %d hajar",num);
}
if(len>=2)
{
num=st[2]-48;
if(num>0)
printf(" %d shata",num);
}
if(len>=0)
{
num=st[0]-48;
if(len>=1)
num=num+10*(st[1]-48);
//num=num*10+st[1]-48;
if(num>0)
printf(" %d",num);
}
if(len==0 && st[0]=='0')
printf(" 0");
printf("\n");
}
}
#include<stdio.h>
#include<string.h>
int main()
{
char st[17],strev[17];
int i,j,temp,a,n,len,t=1,num;
while(scanf("%s",strev)==1)
{
for (len=0;strev[len]!='\0'; len++);
// len=strlen(strev);
for(i=0;i<len;i++)
st[len-i-1]=strev[i];
len--;
printf("%4d.",t);
t++;
if(len==14)
printf(" %d kuti",st[14]-48);
if(len>=12)
{
num=st[12]-48;
if(len>=13)
num=num+10*(st[13]-48);
if(num>0)
printf(" %d lakh",num);
}
if(len>=10)
{
num=st[10]-48;
if(len>=11)
num=num+10*(st[11]-48);
//num=num*10+st[11]-48;
if(num>0)
printf(" %d hajar",num);
}
if(len>=9)
{
num=st[9]-48;
if(num>0)
printf(" %d shata",num);
}
if(len>=7)
{
num=st[7]-48;
if(len>=8)
num=num+10*(st[8]-48);
// num=num*10+st[8]-48;
if(num>0)
printf(" %d",num);
printf(" kuti");
// printf(" %d kuti",num);
}
if(len>=5)
{
num=st[5]-48;
if(len>=6)
num=num+10*(st[6]-48);
// num=num*10+st[6]-48;
if(num>0)
printf(" %d lakh",num);
}
if(len>=3)
{
num=st[3]-48;
if(len>=4)
num=num+10*(st[4]-48);
//num=num*10+st[4]-48;
if(num>0)
printf(" %d hajar",num);
}
if(len>=2)
{
num=st[2]-48;
if(num>0)
printf(" %d shata",num);
}
if(len>=0)
{
num=st[0]-48;
if(len>=1)
num=num+10*(st[1]-48);
//num=num*10+st[1]-48;
if(num>0)
printf(" %d",num);
}
if(len==0 && st[0]=='0')
printf(" 0");
printf("\n");
}
}
Sunday, June 10, 2012
UVA Solution for 10407
#include<stdio.h>
#include<iostream>
#define max 10000
using namespace std;
int gcd(int a,int b)
{
int r=1;
if(a>b)
{
while(r!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
if(b>a)
{
while(r!=0)
{
r=b%a;
b=a;
a=r;
}
return b;
}
if(a==b)
return a;
}
int main()
{
int a,b,x[max],i,num,j,m,d[max];
for(;;)
{
int n=0;
scanf("%d",&x[n]);
if(x[n]==0)
break;
n++;
m=0;
for(;;)
{
scanf("%d",&x[n]);
if(x[n]==0)
break;
//cout<<n<<" "<<m<<" "<<endl;
d[n-1]=x[n]-x[n-1];
if (d[n-1]<0)
d[n-1]=-d[n-1];
if (d[n-1])
n++;
}
num=d[0];
for(j=1;j<n-1;j++)
num=gcd(num,d[j]);
printf("%d\n",num);
i=0;
}
}
#include<iostream>
#define max 10000
using namespace std;
int gcd(int a,int b)
{
int r=1;
if(a>b)
{
while(r!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
if(b>a)
{
while(r!=0)
{
r=b%a;
b=a;
a=r;
}
return b;
}
if(a==b)
return a;
}
int main()
{
int a,b,x[max],i,num,j,m,d[max];
for(;;)
{
int n=0;
scanf("%d",&x[n]);
if(x[n]==0)
break;
n++;
m=0;
for(;;)
{
scanf("%d",&x[n]);
if(x[n]==0)
break;
//cout<<n<<" "<<m<<" "<<endl;
d[n-1]=x[n]-x[n-1];
if (d[n-1]<0)
d[n-1]=-d[n-1];
if (d[n-1])
n++;
}
num=d[0];
for(j=1;j<n-1;j++)
num=gcd(num,d[j]);
printf("%d\n",num);
i=0;
}
}
UVA Solution for 10407
#include<stdio.h>
#define max 10000
int gcd(int a,int b)
{
int r=1;
if(a>b)
{
while(r!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
if(b>a)
{
while(r!=0)
{
r=b%a;
b=a;
a=r;
}
return b;
}
if(a==b)
return a;
}
int main()
{
int a,b,x[max],i,num,j,m,d[max];
for(;;)
{
int n=0;
scanf("%d",&x[n]);
if(x[n]==0)
break;
n++;
m=0;
for(;;)
{
scanf("%d",&x[n]);
if(x[n]==0)
break;
d[m]=x[n]-x[n-1];
if (d[n-1]<0)
d[n-1]=-d[n-1];
if (d[m])
m++;
n++;
}
num=d[0];
for(j=1;j<m;j++)
num=gcd(num,d[j]);
printf("%d\n",num);
i=0;
}
}
#define max 10000
int gcd(int a,int b)
{
int r=1;
if(a>b)
{
while(r!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
if(b>a)
{
while(r!=0)
{
r=b%a;
b=a;
a=r;
}
return b;
}
if(a==b)
return a;
}
int main()
{
int a,b,x[max],i,num,j,m,d[max];
for(;;)
{
int n=0;
scanf("%d",&x[n]);
if(x[n]==0)
break;
n++;
m=0;
for(;;)
{
scanf("%d",&x[n]);
if(x[n]==0)
break;
d[m]=x[n]-x[n-1];
if (d[n-1]<0)
d[n-1]=-d[n-1];
if (d[m])
m++;
n++;
}
num=d[0];
for(j=1;j<m;j++)
num=gcd(num,d[j]);
printf("%d\n",num);
i=0;
}
}
UVA Solution for 10161
#include<stdio.h>
#include<math.h>
int main()
{
long sq,n,distance,x,y;
while(scanf("%ld",&n)==1)
{
if(n==0)
break;
sq=(long)floor(sqrt(n));
distance=n-sq*sq;
if(distance==0)
{
x=1;
y=sq;
}
else if(distance<=sq+1)
{
x=distance;
y=sq+1;
}
else
{
x=sq+1;
y=2*sq+2-distance;
}
if(sq%2==0)
{
int temp=x;
x=y;
y=temp;
}
printf("%ld %ld\n",x,y);
}
}
#include<math.h>
int main()
{
long sq,n,distance,x,y;
while(scanf("%ld",&n)==1)
{
if(n==0)
break;
sq=(long)floor(sqrt(n));
distance=n-sq*sq;
if(distance==0)
{
x=1;
y=sq;
}
else if(distance<=sq+1)
{
x=distance;
y=sq+1;
}
else
{
x=sq+1;
y=2*sq+2-distance;
}
if(sq%2==0)
{
int temp=x;
x=y;
y=temp;
}
printf("%ld %ld\n",x,y);
}
}
UVA Solution for 11541
#include<stdio.h>
#include<string.h>
int decode(char let,int num)
{
if (num==0) return 0;
else for( int i=1;i<=num;i++)
printf("%c",let);
return 0;
}
int main()
{
char line[202],let;
int kase,amnt,i,j,len;
while(scanf("%d\n",&kase)==1)
{
for(i=1;i<=kase;i++)
{
gets(line);
printf("Case %d: ",i);
len=strlen(line);
let=0;
amnt=0;
for(j=0;j<len;j++)
{
if(line[j]>='A' && line[j]<='Z')
{
decode(let,amnt);
let=line[j];
amnt=0;
}
else
amnt=((amnt*10)+(line[j]-48));
if(j==len-1)
decode(let,amnt);
}
printf("\n");
}
}
return 0;
}
#include<string.h>
int decode(char let,int num)
{
if (num==0) return 0;
else for( int i=1;i<=num;i++)
printf("%c",let);
return 0;
}
int main()
{
char line[202],let;
int kase,amnt,i,j,len;
while(scanf("%d\n",&kase)==1)
{
for(i=1;i<=kase;i++)
{
gets(line);
printf("Case %d: ",i);
len=strlen(line);
let=0;
amnt=0;
for(j=0;j<len;j++)
{
if(line[j]>='A' && line[j]<='Z')
{
decode(let,amnt);
let=line[j];
amnt=0;
}
else
amnt=((amnt*10)+(line[j]-48));
if(j==len-1)
decode(let,amnt);
}
printf("\n");
}
}
return 0;
}
UVA Solution for 11728
#include<stdio.h>
#include<math.h>
int list[1001];
void fact()
{
int i,j;
for(i=1;i<=1000;i++)
list[i]=0;
for(i=1;i<=1000;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
list[i]+=j;
}
}
}
int main()
{
fact();
int k,r,i,j,n,kase=1;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
printf("Case %d: ",kase);
r=0;
for(i=1000;i>=1;i--)
{
if(list[i]==n)
{
printf("%d\n",i);
r++;
break;
}
}
if(r==0)
printf("-1\n");
kase++;
}
return 0;
}
#include<math.h>
int list[1001];
void fact()
{
int i,j;
for(i=1;i<=1000;i++)
list[i]=0;
for(i=1;i<=1000;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
list[i]+=j;
}
}
}
int main()
{
fact();
int k,r,i,j,n,kase=1;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
printf("Case %d: ",kase);
r=0;
for(i=1000;i>=1;i--)
{
if(list[i]==n)
{
printf("%d\n",i);
r++;
break;
}
}
if(r==0)
printf("-1\n");
kase++;
}
return 0;
}
UVA Solution for 576
//576
#include<stdio.h>
#include<string.h>
int main()
{
int len,i,j,syl1,syl2,syl3,a,b;
char h[302];
while(gets(h))
{
len=strlen(h);
if(h[0]=='e' && h[1]=='/' && h[2]=='o' && h[3]=='/' && h[4]=='i' && len==5)break;
syl1=syl2=syl3=a=b=0;
for(i=0;i<len;i++)
{
if(h[i]=='/' && a==0)
a=i;
if(h[i]=='/' && a!=0)
b=i;
}
for(i=0;i<len;i++)
{
if(h[i]=='/' && a==0)
a=i;
if(h[i]=='/' && a!=0)
b=i;
}
for(i=0;i<a;i++)
{
if(
(h[i]=='a'|| h[i]=='e'||h[i]=='i'||h[i]=='o'||h[i]=='u'||h[i]=='y')
&&
(!(h[i-1]=='a'|| h[i-1]=='e'||h[i-1]=='i'||h[i-1]=='o'||h[i-1]=='u'||h[i-1]=='y'))
)
syl1++;
}
if(syl1!=5)
printf("1\n");
else
{
for(i=a+1;i<b;i++)
{
if(
(h[i]=='a'|| h[i]=='e'||h[i]=='i'||h[i]=='o'||h[i]=='u'||h[i]=='y')
&&
(! (h[i-1]=='a'|| h[i-1]=='e'||h[i-1]=='i'||h[i-1]=='o'||h[i-1]=='u'||h[i-1]=='y'))
)
syl2++;
}
if(syl2!=7)
printf("2\n");
else
{
for(i=b+1;i<len;i++)
{
if(
(h[i]=='a'|| h[i]=='e'||h[i]=='i'||h[i]=='o'||h[i]=='u'||h[i]=='y')
&&
(!(h[i-1]=='a'|| h[i-1]=='e'||h[i-1]=='i'||h[i-1]=='o'||h[i-1]=='u'||h[i-1]=='y'))
)
syl3++;
}
if(syl3!=5)
printf("3\n");
else
printf("Y\n");
}
}
}
return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
int len,i,j,syl1,syl2,syl3,a,b;
char h[302];
while(gets(h))
{
len=strlen(h);
if(h[0]=='e' && h[1]=='/' && h[2]=='o' && h[3]=='/' && h[4]=='i' && len==5)break;
syl1=syl2=syl3=a=b=0;
for(i=0;i<len;i++)
{
if(h[i]=='/' && a==0)
a=i;
if(h[i]=='/' && a!=0)
b=i;
}
for(i=0;i<len;i++)
{
if(h[i]=='/' && a==0)
a=i;
if(h[i]=='/' && a!=0)
b=i;
}
for(i=0;i<a;i++)
{
if(
(h[i]=='a'|| h[i]=='e'||h[i]=='i'||h[i]=='o'||h[i]=='u'||h[i]=='y')
&&
(!(h[i-1]=='a'|| h[i-1]=='e'||h[i-1]=='i'||h[i-1]=='o'||h[i-1]=='u'||h[i-1]=='y'))
)
syl1++;
}
if(syl1!=5)
printf("1\n");
else
{
for(i=a+1;i<b;i++)
{
if(
(h[i]=='a'|| h[i]=='e'||h[i]=='i'||h[i]=='o'||h[i]=='u'||h[i]=='y')
&&
(! (h[i-1]=='a'|| h[i-1]=='e'||h[i-1]=='i'||h[i-1]=='o'||h[i-1]=='u'||h[i-1]=='y'))
)
syl2++;
}
if(syl2!=7)
printf("2\n");
else
{
for(i=b+1;i<len;i++)
{
if(
(h[i]=='a'|| h[i]=='e'||h[i]=='i'||h[i]=='o'||h[i]=='u'||h[i]=='y')
&&
(!(h[i-1]=='a'|| h[i-1]=='e'||h[i-1]=='i'||h[i-1]=='o'||h[i-1]=='u'||h[i-1]=='y'))
)
syl3++;
}
if(syl3!=5)
printf("3\n");
else
printf("Y\n");
}
}
}
return 0;
}
UVA Solution for 401
#include<stdio.h>
#include<string.h>
int a,b,c,len,i,j;
int palindrome(char line [])
{
int k=1;
len=strlen(line);
for(i=0,j=len-1;i<len,j>=0;i++,j--)
{
if (line[i]==line[j] )
continue;
else
{
k=0;
break;
}
}
if(k==1)
return 1;
else
return 0;
}
int mirpalin(char line[])
{
int k=0;
len=strlen(line);
for(i=0;i<len;i++)
{
if(line[i]=='A'||line[i]=='H'||line[i]=='I'||line[i]=='L'||
line[i]=='M'||line[i]=='O'||line[i]=='T'||line[i]=='U'||
line[i]=='V'||line[i]=='W'||line[i]=='X'||
line[i]=='Y'||
line[i]=='1'||line[i]=='8'||line[i]=='0')
k++;
}
if(k==len)
return 1;
else
return 0;
}
int mirrorstring(char line[])
{
int k,a=1;
len=strlen(line);
for(i=0;i<len;i++)
{
if(line[i]=='E')
line[i]='3';
else if(line[i]=='J')
line[i]='L';
else if(line[i]=='0')
line[i]='O';
else if(line[i]=='S')
line[i]='2';
else if(line[i]=='Z')
line[i]='5';
else
continue;
}
a=palindrome(line);
if(a==1)
return 1;
else
return 0;
}
int main()
{
char line[22];
int pd,ms,mp;
while(gets(line))
{
len=strlen(line);
for(i=0;i<len;i++)
printf("%c",line[i]);
pd=palindrome(line);
if(pd==1)
{
mp=mirpalin(line);
if(mp==1)
printf(" -- is a mirrored palindrome.\n\n");
else
printf(" -- is a regular palindrome.\n\n");
}
else
{
ms=mirrorstring(line);
if(ms==1)
printf(" -- is a mirrored string.\n\n");
else
printf(" -- is not a palindrome.\n\n");
}
}
}
#include<string.h>
int a,b,c,len,i,j;
int palindrome(char line [])
{
int k=1;
len=strlen(line);
for(i=0,j=len-1;i<len,j>=0;i++,j--)
{
if (line[i]==line[j] )
continue;
else
{
k=0;
break;
}
}
if(k==1)
return 1;
else
return 0;
}
int mirpalin(char line[])
{
int k=0;
len=strlen(line);
for(i=0;i<len;i++)
{
if(line[i]=='A'||line[i]=='H'||line[i]=='I'||line[i]=='L'||
line[i]=='M'||line[i]=='O'||line[i]=='T'||line[i]=='U'||
line[i]=='V'||line[i]=='W'||line[i]=='X'||
line[i]=='Y'||
line[i]=='1'||line[i]=='8'||line[i]=='0')
k++;
}
if(k==len)
return 1;
else
return 0;
}
int mirrorstring(char line[])
{
int k,a=1;
len=strlen(line);
for(i=0;i<len;i++)
{
if(line[i]=='E')
line[i]='3';
else if(line[i]=='J')
line[i]='L';
else if(line[i]=='0')
line[i]='O';
else if(line[i]=='S')
line[i]='2';
else if(line[i]=='Z')
line[i]='5';
else
continue;
}
a=palindrome(line);
if(a==1)
return 1;
else
return 0;
}
int main()
{
char line[22];
int pd,ms,mp;
while(gets(line))
{
len=strlen(line);
for(i=0;i<len;i++)
printf("%c",line[i]);
pd=palindrome(line);
if(pd==1)
{
mp=mirpalin(line);
if(mp==1)
printf(" -- is a mirrored palindrome.\n\n");
else
printf(" -- is a regular palindrome.\n\n");
}
else
{
ms=mirrorstring(line);
if(ms==1)
printf(" -- is a mirrored string.\n\n");
else
printf(" -- is not a palindrome.\n\n");
}
}
}
UVA Solution for 305
#include<stdio.h>
int x[15]={0,2,7,5,30,169,441,1872,7632,1740,
93313,459901,1358657,2504881};
//long x[15]={0,2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};
int main()
{
int n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
else
{
printf("%d\n",x[n]);
}
}
}
int x[15]={0,2,7,5,30,169,441,1872,7632,1740,
93313,459901,1358657,2504881};
//long x[15]={0,2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};
int main()
{
int n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
else
{
printf("%d\n",x[n]);
}
}
}
UVA Solution for 11089
//11089
#include<stdio.h>
int fib[] = {
1,2,3,5,8,13,21,34,55,89,144,233,377,610,
987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,
196418,317811,514229,832040,1346269,2178309,3524578,5702887,
9227465,14930352,24157817,39088169,63245986,102334155,
165580141,267914296,433494437,701408733,1134903170
};
int main()
{
int i,j,t,s,sz,n;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
{
for(j = 43; j >= 0; j--)
{
if(n>=fib[j])
break;
}
sz = 1;
s= fib[j];
putchar('1');
//printf("1");
for(j--; j>=0; j--)
{
if(fib[j] + s <= n && sz)
{
putchar('1');
//printf("1");
s +=fib[j];
sz = 0;
continue;
}
else
putchar('0');
//printf("0");
sz = 1;
}
putchar('\n');
//printf("\n");
}
}
return 0;
}
#include<stdio.h>
int fib[] = {
1,2,3,5,8,13,21,34,55,89,144,233,377,610,
987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,
196418,317811,514229,832040,1346269,2178309,3524578,5702887,
9227465,14930352,24157817,39088169,63245986,102334155,
165580141,267914296,433494437,701408733,1134903170
};
int main()
{
int i,j,t,s,sz,n;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
{
for(j = 43; j >= 0; j--)
{
if(n>=fib[j])
break;
}
sz = 1;
s= fib[j];
putchar('1');
//printf("1");
for(j--; j>=0; j--)
{
if(fib[j] + s <= n && sz)
{
putchar('1');
//printf("1");
s +=fib[j];
sz = 0;
continue;
}
else
putchar('0');
//printf("0");
sz = 1;
}
putchar('\n');
//printf("\n");
}
}
return 0;
}
UVA Solution for 440
//151
#include<stdio.h>
int func(int n,int mod)
{
int i,j,c=0,x,k;
int a[200];
for(i=1;i<=n;i++)
a[i]=1;
a[1]=0;
x=1;
for(i=1;;i++)
{
for(j=1;j<=n;j++)
{
if(a[j]==1)
c++;
if(c==mod)
{
a[j]=0;
c=0;
x++;
k=j;
}
if(x==n)
break;
}
if(x==n)
break;
}
return k;
}
int main()
{
int i,j,n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
for(i=1;;i++)
{
j=func(n,i);
if(j==2)
{
printf("%d\n",i);
break;
}
}
}
}
#include<stdio.h>
int func(int n,int mod)
{
int i,j,c=0,x,k;
int a[200];
for(i=1;i<=n;i++)
a[i]=1;
a[1]=0;
x=1;
for(i=1;;i++)
{
for(j=1;j<=n;j++)
{
if(a[j]==1)
c++;
if(c==mod)
{
a[j]=0;
c=0;
x++;
k=j;
}
if(x==n)
break;
}
if(x==n)
break;
}
return k;
}
int main()
{
int i,j,n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
for(i=1;;i++)
{
j=func(n,i);
if(j==2)
{
printf("%d\n",i);
break;
}
}
}
}
UVA Solution for 151
//151
#include<stdio.h>
int func(int n,int mod)
{
int i,j,c=0,x,k;
int a[200];
for(i=1;i<=n;i++)
a[i]=1;
a[1]=0;
x=1;
for(i=1;;i++)
{
for(j=1;j<=n;j++)
{
if(a[j]==1)
c++;
if(c==mod)
{
a[j]=0;
c=0;
x++;
k=j;
}
if(x==n)
break;
}
if(x==n)
break;
}
return k;
}
int main()
{
int i,j,n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
for(i=1;;i++)
{
j=func(n,i);
if(j==13)
{
printf("%d\n",i);
break;
}
}
}
}
#include<stdio.h>
int func(int n,int mod)
{
int i,j,c=0,x,k;
int a[200];
for(i=1;i<=n;i++)
a[i]=1;
a[1]=0;
x=1;
for(i=1;;i++)
{
for(j=1;j<=n;j++)
{
if(a[j]==1)
c++;
if(c==mod)
{
a[j]=0;
c=0;
x++;
k=j;
}
if(x==n)
break;
}
if(x==n)
break;
}
return k;
}
int main()
{
int i,j,n;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
for(i=1;;i++)
{
j=func(n,i);
if(j==13)
{
printf("%d\n",i);
break;
}
}
}
}
Subscribe to:
Posts (Atom)