#include<iostream>
using namespace std;
int main()
{
for(int i=1;i<=9;++i)
{
for(int j=1;j<=9;++j)
{
printf("%dx%d=%d\n" , i , j , i*j);
}
}
return 0;
}
List of Top 3 Hills
#include<iostream>
#define element 10
using namespace std;
int height[element];
int number;
int main()
{
for(int i=0;i<element;++i)
{
cin >> height[i];
}
for(int i=0;i<element;++i)
{
for(int j=i;j<element;++j)
{
if(height[i]<height[j])
{
number = height[i];
height[i] = height[j];
height[j] = number;
}
}
}
printf("%d\n%d\n%d\n",height[0],height[1],height[2]);
return 0;
}
Digit Number
#include<iostream>
int a, b, n, m;
int main()
{
while(std::cin>>a>>b)
{
n = a + b;
m = 1;
while(n>=10)
{
n=n/10;
++m;
}
printf ("%d\n",m);
}
return 0;
}
Is it a Right Triangle?
#include<iostream>
unsigned short a, b, c;
int m;
bool flag;
int main()
{
std::cin >> m;
for(int i = 0;i < m;++i)
{
std::cin >> a >> b >> c;
if (a==0||b==0||c==0)
{
continue;
}
flag = false;
if((a*a)+(b*b)==(c*c))
{
flag = true;
}
else if((a*a)+(c*c)==(b*b))
{
flag = true;
}
else if((b*b)+(c*c)==(a*a))
{
flag = true;
}
if(flag==false)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}
Simultaneous Equation
#include<iostream>
#include<math.h>
double a, b, c, d, e, f;
int main()
{
while(std::cin>>a>>b>>c>>d>>e>>f)
{
double x = (e*c-b*f)/(a*e-b*d);
double y = (-d*c+a*f)/(a*e-b*d);
printf("%.3lf %.3lf\n",x+(1e-10),y+(1e-10));
}
return 0;
}
GCD and LCM
#include<iostream>
using namespace std;
int a, b;
int change;
int GCD(int m, int n)
{
if((0==m)||(0==n))
{
return 0;
}
while(m!=n)
{
if(m>n)
{
m=m-n;
}
else
{
n=n-m;
}
}
return m;
}
int LCM(int m,int n)
{
if((0==m)||(0==n))
{
return 0;
}
return m/GCD(m,n)*n;
}
int main()
{
while(cin>>a>>b)
{
printf("%d %d\n",GCD(a,b),LCM(a,b));
}
}
Reverse Sequence
#include<iostream>
using namespace std;
char str[20];
int main()
{
cin>>str;
for(int i=0;i<20;++i)
{
if(str[19-i]!=0)
{
printf("%c",str[19-i]);
}
}
printf("\n");
}
Debt Hell
#include<iostream>
using namespace std;
double money = 100000;
int i;
int main()
{
cin>>i;
for(i;i>0;--i)
{
money *= 1.05;
money = (long)(money/1000+0.99)*1000;
}
printf("%.0lf\n",money);
}
Sum of 4 Integers
#include<iostream>
using namespace std;
int n;
int count;
int main()
{
while(cin>>n)
{
for(int i=0;i<=9;++i)
{
for(int j=0;j<=9;++j)
{
for(int k=0;k<=9;++k)
{
for(int l=0;l<=9;++l)
{
if(i+j+k+l==n)
{
++count;
}
}
}
}
}
cout<<count<<endl;
count = 0;
}
}
Prime Number
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int count = 0;
bool *flag = new bool[n+1]();
for(int i=2;i<=n;++i)
{
if (flag[i])
{
continue;
}
for(int j=i*2;j<=n;j+=i)
{
flag[j] = true;
}
}
flag[0]=true;
flag[1]=true;
for(int i=0;i<=n;++i)
{
if(!flag[i])
{
++count;
}
}
cout<<count<<endl;
}
}
0 件のコメント:
コメントを投稿