Reproduced in this article:
Chapter I.
Exercise 1-1
#include <stdio.h>
int main ()
{
int a,b,c;
Double D;
scanf ("%d%d%d", &a,&b,&c);
D= (Double) (A+B+C);
printf ("%.3lf\n", d/3.0);
return 0;
}
Exercise 1-2
#include <stdio.h>
int main ()
{
int F;
Double C;
scanf ("%d", &f);
c=5* (F-32)/9;
printf ("%.3lf\n", c);
return 0;
}
Exercise 1-3
#include <stdio.h>
int main ()
{
int n;
scanf ("%d", &n);
printf ("%d\n", (n (1+n))/2);
return 0;
}
Exercise 1-4
#include <stdio.h>
#include <math.h>
#define PI 4.0*atan (1.0)
int main ()
{
int n;
scanf ("%d", &n);
printf ("%lf\n", Sin ((pi*n)/180));
printf ("%lf\n", cos ((pi*n)/180));
return 0;
}
Exercise 1-5
#include <stdio.h>
int main ()
{
Double x1,y1,x2,y2,a;
scanf ("%lf%lf%lf%lf", &x1,&y1,&x2,&y2);
A=sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));
printf ("%lf\n", a);
return 0;
}
Exercise 1-6
#include <stdio.h>
int main ()
{
int n;
scanf ("%d", &n);
if (n%2==0)
{
printf ("yes\n");
}
Else
{
printf ("no\n");
}
return 0;
}
Exercise 1-7
#include <stdio.h>
int main ()
{
int n;
Double A;
scanf ("%d", &n);
a=n*95.0;
if (a<300)
{
printf ("%.2lf\n", a);
}
Else
{
printf ("%.2lf\n", a*0.85);
}
return 0;
}
Exercise 1-8
#include <stdio.h>
#include <math.h>
int main ()
{
Double N;
scanf ("%lf", &n);
printf ("%.2lf", Fabs (n));
return 0;
}
Exercise 1-9
#include <stdio.h>
int main ()
{
int a,b,c;
scanf ("%d%d%d", &a,&b,&c);
if (a==b&&b==c)
{
printf ("no\n");
}
if ((a*a+b*b==c*c) | | | (a*a+c*c==b*b) | | (b*b+c*c==a*a))
{
printf ("yes\n");
}
Else
{
printf ("no\n");
}
return 0;
}
Exercise 1-10
#include <stdio.h>
int main ()
{
int n;
scanf ("%d", &n);
if (n%4==0)
{
if (n%100!=0)
{
printf ("no\n");
}
Else
{
if (n%400==0)
{
printf ("yes\n");
}
Else
{
printf ("no\n");
}
}
}
Else
{
printf ("no\n");
}
return 0;
}
Chapter II
Exercise 2-1
#include <stdio.h>
int main ()
{
int n,count=0;
scanf ("%d", &n);
while (n>0)
{
count++;
N=N/10;
}
printf ("%d\n", count);
return 0;
}
Exercise 2-2
#include <stdio.h>
int main ()
{
int a,b,c;
for (int i=100;i<=999;i++)
{
a=i%10;
b=i/10%10;
c=i/100;
if (i==a*a*a+b*b*b+c*c*c)
{
printf ("%d\n", I);
}
}
return 0;
}
Exercise 2-3
#include <stdio.h>
int main ()
{
int i,a,b,c;
scanf ("%d%d%d", &a,&b,&c);
for (i=10;i<=100;i++)
{
if (i%3==a&&i%5==b&&i%7==c)
{
printf ("%d\n", I);
}
}
if (i==101)
{
printf ("No answer\n");
}
return 0;
}
Exercise 2-4
#include <stdio.h>
int main ()
{
int i,j,k,n;
scanf ("%d", &n);
for (i=n;i>0;i--)
{
for (k=0;k<n-i;k++)
{
printf ("");
}
for (j=0;j<2*i-1;j++)
{
printf ("#");
}
printf ("\ n");
}
return 0;
}
Exercise 2-5
Paper title, the South Mail contest basically does not involve ...
Exercise 2-6
#include <stdio.h>
int main ()
{
int i,n;
Double sum=1.0;
scanf ("%d", &n);
for (i=2;i<=n;i++)
{
sum+= (1.0/i);
}
printf ("%.3lf\n", sum);
return 0;
}
Exercise 2-7
#include <stdio.h>
#include <math.h>
int main ()
{
int t=-1;
Double a=1.0,sum=1.0;
while (Fabs (a) >=0.000001)
{
a=1.0/(a+2);
A=a*t;
Sum=sum+a;
t=t* (-1);
}
printf ("%.9lf\n", sum);
return 0;
}
Exercise 2-8
#include <stdio.h>
int main ()
{
int i,n,m,temp;
Double sum=0;
scanf ("%d%d", &n,&m);
if (n>m)
{
Temp=n;
N=m;
M=temp;
}
for (i=n;i<=m;i++)
{
sum=sum+ (1.0/i/i);
}
printf ("%.5lf\n", sum);
return 0;
}
Exercise 2-9
Special usage of printf: The format for M.N can be represented as follows
Char ch[20];
printf ("%*.*s\n", m,n,ch);
The front of the * defines the total width, and the back defines the number of outputs. corresponding to the outer parameters m and n respectively. The benefit of this approach is that the parameters m and n can be assigned outside the statement to control the output format.
#include <stdio.h>
int main ()
{
int a,b,c;
scanf ("%d%d%d", &a,&b,&c);
printf ("%.*lf\n", C, (double) A/b);
return 0;
}
Exercise 2-10
#include <stdio.h>
int main ()
{
int a,b,c,d,e,f,g,h,i;
for (a=1;a<=9;a++)
{
for (b=1;b<=9;b++)
{
for (c=1;c<=9;c++)
{
for (d=1;d<=9;d++)
{
for (e=1;e<=9;e++)
{
for (f=1;f<=9;f++)
{
for (g=1;g<=9;g++)
{
for (h=1;h<=9;h++)
{
for (i=1;i<=9;i++)
{
if ((a*100+b*10+c) ==1* (d*100+e*10+f)) && (a*100+b*10+c) ==1* (g*100+h*10+i) && (a!=b) & & (A!=c) && (a!=d) && (a!=e) && (a!=f) && (a!=g) && (a!=h) && (a!=i) && (b!=c) && (b!=d) && (b!=e) && (b!=f) && (b!=g) && (b!=h) && (b!= i) && (c!=d) && (c!=e) && (c!=f) && (c!=g) && (c!=h) && (c!=i) && (d !=e) && (d!=f) && (d!=g) && (d!=h) && (d!=i) && (e!=f) && (e!=g) && (e!=h) && (e!=i) && (f!=g) && (f!=h) && (f!=i) && (g!=h) && (g!=i) & & (H!=i))
{
printf ("%d,%d,%d\n", a*100+b*10+c,d*100+e*10+f,g*100+h*10+i);
}
}
}
}
}
}
}
}
}
}
return 0;
}
Chapter III
Exercise 3-1
#include <stdio.h>
#include <string.h>
int main ()
{
int I,a[101],n,max;
memset (A,sizeof (a), 0);
while (scanf ("%d", &n) ==1)
{
a[n]++;
}
MAX=A[0];
for (i=1;i<101;i++)
{
if (A[i]>=max)
{
Max=a[i];
}
}
for (i=0;i<101;i++)
{
if (A[i]==max)
{
printf ("%d", I);
}
}
printf ("\ n");
return 0;
}
Exercise 3-2
#include <stdio.h>
#include <ctype.h>
Char s[1000];
int main ()
{
Char ch;
int i,j,m=0,sumlong=0,count=0;
while (1)
{
scanf ("%c", &ch);
if (ch== ' \ n ' | | ch==eof)
{
Break
}
Else
{
S[m++]=ch;
}
}
for (i=m-1;i>0;i--)
{
if (s[i]== "&&s[i-1]==")
{
for (j=i-1;j<m-1;j++)
{
S[J]=S[J+1];
}
m--;
}
}
for (i=0;i<m;i++)
{
if (Isalpha (S[i]))
{
sumlong++;
}
else if (s[i]== ')
{
count++;
}
}
printf ("%.2lf\n", (Double) ((sumlong+count+1)/(count+1)));
return 0;
}
Exercise 3-3 (re-do!!! )
#include <stdio.h>
#include <ctype.h>
#define MOD 1000
Char s[10000];
Char buf[10000];
int main ()
{
int i,m=0,n=0,sum=1;
Char ch;
while (1)
{
scanf ("%c", &ch);
if (ch==eof| | ch== ' \ n ')
{
Break
}
Else
{
S[m++]=ch;
}
}
for (i=0;i<m;i++)
{
if (IsDigit (S[i]))
{
buf[n++]=s[i]-' 0 ';
}
}
for (i=0;i<n;i++)
{
Sum=sum*buf[i];
}
printf ("%d\n", sum%mod);
return 0;
}
Exercise 3-4
Exercise 3-5
#include <stdio.h>
Char a[1000][1000];
int main ()
{
int i,j,n;
scanf ("%d", &n);
scanf ("");
char temp;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
scanf ("%c", &a[i][j]);
}
}
for (i=0;i<n;i++)
{
for (j=i;j<n;j++)
{
TEMP=A[I][J];
A[i][j]=a[j][i];
A[j][i]=temp;
}
}
for (i=n-1;i>=0;i--)
{
for (j=0;j<n;j++)
{
printf ("%c", A[i][j]);
}
printf ("\ n");
}
return 0;
}
Exercise 3-6
#include <stdio.h>
int main ()
{
int b,n,m=0;
Char p[100];
scanf ("%d%d", &b,&n);
while (b!=0)
{
p[m++]=b%n+ ' 0 ';
b=b/n;
}
for (int i=m-1;i>=0;i--)
{
printf ("%c", P[i]);
}
printf ("\ n");
return 0;
}
Exercise 3-7
#include <stdio.h>
int NDJC (int n,int m)
{
int i,a=1;
for (i=0;i<n;i++)
{
A*=m;
}
return A;
}
int main ()
{
int i,b,n,p[100],m=0,a=0;
scanf ("%d%d", &n,&b);
while (n>0)
{
p[m++]=n%10;
N=N/10;
}
m--;
for (i=m;i>=0;i--)
{
A+=P[I]*NDJC (I,B);
}
printf ("%d\n", a);
return 0;
}
Algorithmic Competition Introductory Classic (Rujia) the answer to the first three chapters of a post-lesson exercise