1.输出一个短句“Programming in C is fun!”。
#include<stdio.h>
int main(void){
printf("Programming in C is fun!");
return 0;
}
#include<stdio.h>
int main()
{
int i,j;
for( i=0; i<4; i++ )
{
for( j=0; j<i; j++)
printf(" ");
for( j=4-j; j>0; j-- )
printf("* ");
printf("\n");
}
return 0;
}
3.
#include <stdio.h>
int main()
{
int fahr,celsius;
fahr = 150;
celsius = 5 * (fahr - 32 ) / 9;
printf("fahr = %d, celsius = %d",fahr,celsius);
return 0;
}
#include <stdio.h>
int main(){
double height = 0.5*10*3*3;
printf("height = %.2lf",height);
return 0;
}
#include <stdio.h>
int main(){
int F,C;
scanf("%d",&F);
C = 5*(F-32)/9;
printf("Celsius = %d",C);
return 0;
}
#include <stdio.h>
int main(){
int A,B;
scanf("%d %d",&A,&B);
printf("%d + %d = %d\n",A,B,A+B);
printf("%d - %d = %d\n",A,B,A-B);
printf("%d * %d = %d\n",A,B,A*B);
printf("%d / %d = %d\n",A,B,A/B);
return 0;
}
#include <stdio.h>
int main(){
float x,y;
scanf("%f",&x);
if(x != 0){
y = 1/x;
} else{
y = 0;
}
printf("f(%.1f) = %.1f",x,y);
return 0;
}
8.
#include <stdio.h>
#include <math.h>
int main(){
float x,y;
scanf("%f",&x);
if(x > 0 ||x == 0){
y = pow(x,0.5);
} else{
y = pow(x+1,2) + 2*x+1/x;
}
printf("f(%.2f) = %.2f",x,y);
return 0;
}
#include <stdio.h>
int main()
{
int lower,upper;
double celsius;
scanf("%d %d",&lower,&upper);
if(lower>upper || upper>100) printf("Invalid.");
else
{
printf("fahr celsius\n");
for(int i=lower;i<=upper;i=i+2)
{
celsius=5.0*(i-32)/9;
printf("%d %5.1lf\n",i,celsius);
}
}
return 0;
}
#include <stdio.h>
int main(){
int a;
float temp,sum = 0;
scanf("%d",&a);
for(int i = 1;i<=a;i++){
temp = 1.0/i;
sum+=temp;
}
printf("sum = %.6lf",sum);
return 0;
}
#include <stdio.h>
int main(){
int a;
double temp = 1.0,sum = 0.0;
scanf("%d",&a);
for(int i = 1;i<=a;i++){
sum+=1/temp;
temp+=2;
}
printf("sum = %.6lf",sum);
return 0;
}
#include <stdio.h>
int main()
{
int N,sign=1;
scanf("%d",&N);
double sum=0.0,temp=1.0;
for(int i=1;i<=N;i++)
{
sum+=sign*1.0/temp;
sign=-sign;
temp+=3;
}
printf("sum = %.3lf",sum);
return 0;
}
#include <stdio.h>
#include <math.h>
int main(){
int a,b;
scanf("%d",&a);
for(int i = 0;i<=a;i++){
b = pow(3,i);
printf("pow(3,%d) = %d\n",i,b);
}
return 0;
}
#include <stdio.h>
double fact(int n);
int main(){
int a,b,result;
scanf("%d %d",&a,&b);
result = fact(b)/ fact(a)/ fact(b-a);
printf("result = %d",result);
return 0;
}
double fact(int n){
int i,sum=1;
for(i = 1;i<=n;i++){
sum*=i;
}
return sum;
}
15
# include <stdio.h>
int main(){
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
printf("Sum = %d; Average = %.1lf",a+b+c+d,(a+b+c+d)/4.0);
return 0;
}
# include <stdio.h>
int main(){
int a[4],sum = 0;
for(int i = 0;i<4;i++){
scanf("%d",&a[i]);
sum += a[i];
}
printf("Sum = %d; Average = %.1lf",sum,sum/4.0);
return 0;
}
#include <stdio.h>
int main(){
int a;
double cost;
scanf("%d",&a);
if(a<=50&&a>0){
cost = 0.53*a;
printf("cost = %.2lf",cost);
} else if(a>50){
cost = 50*0.53+(a-50)*0.58;
printf("cost = %.2lf",cost);
} else{
printf("Invalid Value!");
}
return 0;
}
#include <stdio.h>
#include <math.h>
int main(){
int a,b;
double sum1 = 0,sum2 = 0;
scanf("%d %d",&a,&b);
for(int i = a;i<=b;i++){
sum1+=pow(i,2);
sum2+=1.0/i;
}
printf("sum = %.6f",sum1+sum2);
return 0;
}
#include <stdio.h>
int main(){
int a,flag = 1;
double b = 1.0;
double sum = 0;
scanf("%d",&a);
for(int i = 1;i<=a;i++){
sum+=flag*(b/(2*b-1));
flag=-flag;
b++;
}
printf("%.3f",sum);
return 0;
}
#include <stdio.h>
#include <math.h>
int main(){
int a;
double b = 1.0;
double sum;
scanf("%d",&a);
for(int i = 1;i<=a;i++){
sum+=sqrt(b);
b++;
}
printf("%.2f",sum);
return 0;
}
#include <stdio.h>
int main(){
int a,sum = 0;
scanf("%d",&a);
for(int i = 1;i<=a;i++){
int b=1;
for(int j = 1;j<=i;j++){
b *= j;
}
sum += b;
}
printf("%d",sum);
return 0;
}
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
if(n>0){
printf("sign(%d) = 1",n);
} else if(n == 0)
printf("sign(%d) = 0",n);
else
printf("sign(%d) = -1",n);
return 0;
}
#include<stdio.h>
int main()
{
int i=1;
int grade=0,total=0;
int count=0;
double average=0,N=0;
scanf("%lf",&N);
for(i=1;i<=N;i++){
scanf("%d",&grade);
total=total+grade;
average=1.0*total/N;
if(grade>=60){
count++;
}
}
printf("average = %.1f\n",average);
printf("count = %d\n",count);
return 0;
}
23.
#include <stdio.h>
int main(void)
{
char c;
int i, letter = 0, blank = 0, digit = 0, other = 0;
for (i = 0; i < 10; i++)
{
c = getchar();
if (c >= '0' && c <= '9')
digit++;
else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
letter++;
else if (c == ' ')
blank++;
else if (c == '\n')
blank++;
else
other++;
}
printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);
return 0;
}
24
#include<stdio.h>
int main(){
int year,i,cnt=0;
scanf("%d",&year);
if(2000<year&&year<=2100){
for(i=2001;i<=year;i++){
if((i%4==0&&i%100!=0)|| (i%400==0)){
printf("%d\n",i);
cnt++;}
}
if(cnt==0) printf("None\n");
}else{
printf("Invalid year!");
}
return 0;
}
25
#include <stdio.h>
int main(){
int a;
scanf("%d",&a);
if(a>90)
printf("A");
else if(a>=80&&a<90)
printf("B");
else if(a>=70&&a<80)
printf("C");
else if(a>=60&&a<70)
printf("D");
else
printf("E");
return 0;
}
26
#include<stdio.h>
int main(void)
{
printf("[1] apple\n[2] pear\n[3] orange\n[4] grape\n[0] exit\n");
int a, k;
for(a=0;a<=4;a++)
{
scanf("%d",&k);
if(k==0)
{
break;
}
switch(k)
{
case 1:printf("price = 3.00\n");
break;
case 2:printf("price = 2.50\n");
break;
case 3:printf("price = 4.10\n");
break;
case 4:printf("price = 10.20\n");
break;
default:printf("price = 0.00\n");
break;
}
}
return 0;
}
27
#include<stdio.h>
int main()
{
int x,y,z,min;
scanf("%d %d %d",&x,&y,&z);
if(x>y)
{
min = x;
x = y;
y = min;
}
if(x>z)
{
min = x;
x = z;
z = min;
}
if(y>z)
{
min = y;
y = z;
z = min;
}
printf("%d->%d->%d",x,y,z);
return 0;
}
28
#include<stdio.h>
int main()
{
int a,b;
int exceed;
scanf("%d %d",&a,&b);
exceed=(double)(a-b)/b*100+0.5;
if(exceed<10){
printf("OK\n");
}
else
if(exceed<50){
printf("Exceed %d%%. Ticket 200\n", exceed);
}
else
{
printf("Exceed %d%%. License Revoked\n", exceed);
}
return 0;
}
29
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
double mile = 0;
int time = 0;
double price, price1, price2;
scanf("%lf %d", &mile, &time);
if (mile <= 3)
{
price1 = 10;
}
else if (mile <= 10)
{
price1 = 10 + (mile - 3) * 2.0;
}
else
{
price1 = 10 + (10 - 3)*2.0 + (mile - 10)*3.0;
}
price2 = time/ 5 * 2;
price = price1 + price2;
printf("%.0f\n", price);
system("pause");
return 0;
}
30
#include<stdio.h>
int main(void)
{
int i, n, m, A, B, C, D, E;
A = 0;
B = 0;
C = 0;
D = 0;
E = 0;
scanf("%d", &n);
for(i = 1;i<=n;i++)
{
scanf("%d", &m);
if(m>=90&&m<=100)
{
A ++;
}
if(m>=80&&m<90)
{
B ++;
}
if(m>=70&&m<80)
{
C ++;
}
if(m>=60&&m<70)
{
D ++;
}
if(m>=0&&m<60)
{
E ++;
}
}
printf("%d %d %d %d %d", A, B, C, D, E);
return 0;
}
31
#include<stdio.h>
#include<math.h>
int main()
{
float x1,y1,x2,y2,x3,y3;
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
float a,b,c,A,L;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
if(a+b>c&&a+c>b&&b+c>a)
{
L=a+b+c;
float p=L/2.0;
A=sqrt(p*(p-a)*(p-b)*(p-c));
printf("L = %.2f, A = %.2f\n",L,A);
}
else
printf("Impossible");
return 0;
}
32
#include<stdio.h>
#include<math.h>
int main()
{int flag=1, i=1;
double sum=0,n=1.0,eps;
scanf("%lf",&eps);
if(eps>=1)
printf("sum = %.6f",n);
else
{
while(fabs(n)>eps)
{n=flag*1.0/i;
sum=sum+n;
i+=3;
flag=-flag;
}
printf("sum = %.6f",sum);}
return 0;
}
33
#include <stdio.h>
int main()
{
int rand_number, n;
scanf("%d %d", &rand_number, &n);
int i;
int m;
int flag = 0;
for (i = 1; i <= n; i++)
{
scanf("%d", &m);
if (m < 0)
break;
if (m > rand_number)
printf("Too big\n");
if (m < rand_number)
printf("Too small\n");
if (m == rand_number)
{
if (i == 1)
{
flag = 1;
printf("Bingo!\n");
break;
}
if (i == 2 || i == 3)
{
flag = 1;
printf("Lucky You!\n");
break;
}
if (i > 3)
{
flag = 1;
printf("Good Guess!\n");
break;
}
}
}
if (flag == 0)
printf("Game Over\n");
return 0;
}
34
#include<stdio.h>
double facter(int i)
{
int j=1;
double sum=1;
for(j=1;j<=i;j++)
sum=sum*j;
return sum;
}
int main()
{
int n;
double sum=1.0,a;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
a=1.0/facter(i);
sum=sum+a;
}
printf("%.8lf",sum);
return 0;
}
35
# include <stdio.h>
# include <stdlib.h>
# define MAXS 1001
int main() {
int n,i = 0,j,min;
int number[MAXS];
scanf("%d",&n);
while(i < n) {
scanf("%d",&number[i]);
i += 1;
}
min = number[0];
for (j=1;j<i;j++) {
if (min >= number[j]) {
min = number[j];
}
}
printf("min = %d",min);
return 0;
}
36
#include<stdio.h>
int main()
{
int M, N,i,g,h=0,sum=0;
scanf("%d %d", &M, &N);
for (i = M; i <= N; i++)
{
for (g = 2; g <= i; g++)
{
if (i % g == 0)
break;
}
if (i == g)
{
sum += i;
h++;
}
}
printf("%d %d",h,sum);
return 0;
}
37
#include<stdio.h>
int main()
{
int n,sum=0;
scanf("%d",&n);
while(n>0)
{
if(n%2==1)
sum=sum+n;
scanf("%d",&n);
}
printf("%d",sum);
return 0;
}
38
#include<stdio.h>
double fun(int n)
{
if(n==1||n==0) return 1;
else return n*fun(n-1);
}
int main()
{
double n;
scanf("%lf",&n);
int i;
double sum=1.0;
double n1=n;
for(i=1;;i++)
{
double t=n1/fun(i);
sum+=t;
n1*=n;
if(t<0.00001)break;
}
printf("%.4lf\n",sum);
return 0;
}
39
#include<stdio.h>
int main(){
int n,i;
double numerator,denominator;
double sum,item,flag;
sum=0;
scanf("%d",&n);
if(n>=1){
denominator=1;
numerator=2;
item=numerator/denominator;
sum=sum+item;
if(n>=2){
for(i = 2;i <= n;i++){
flag=numerator;
numerator=denominator+flag;
denominator=flag;
item=1.0*numerator/denominator;
sum=sum+item;
}
}
}
printf("%.2f",sum);
return 0;
}
40
#include <stdio.h>
#include <math.h>
int main()
{
int a,n,sum,item;
item=0;
sum=0;
scanf("%d %d",&a,&n);
if(a<=9&&n<=9){
for(int i=1;i<=n;i++){
item=a*pow(10,i-1)+item;
sum+=item;
}
}
printf("s = %d",sum);
return 0;
}
41
#include <stdio.h>
#include <stdlib.h>
int main() {
int x,k=0,total,count=0,i,j;
scanf("%d",&x);
for(i=(x-3)/5;i>=1;i--)
{
for(j=(x-5*i-1)/2;j>=1;j--)
{
k=x-5*i-2*j;
total=i+j+k;
printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n",i,j,k,total);
count++;
}
}
printf("count = %d",count);
return 0;
}
42
#include <stdio.h>
#include <math.h>
int main()
{
int n = 0, start, temp, reigon;
scanf("%d",&n);
start = pow(10, n - 1);
reigon = pow(10, n);
for (start; start < reigon; start++)
{
int sum = 0,temp = start;
while (sum <= start && temp != 0) {
int mod = temp % 10;
int nn = 1;
for (int j = 0; j < n; j++)
nn *= mod;
sum += nn;
temp /= 10;
}
if (start == sum)
{
printf("%d\n",start);
}
}
return 0;
}
43
#include<stdio.h>
int main ()
{
int a,b,c,d,e;
scanf("%d %d",&a,&b);
if (a>b)
{
a=a; b=b; }
else{ c=a; a=b; b=c;}
d=a;
e=b;
if (a%b==0)
c=b;
while (a%b!=0)
{
c=a%b;
a=b;
b=c;
}
printf("%d %d",c,d*e/c);
return 0;
}
44
#include <stdio.h>
double rebound(long height,long n);
int main(){
long height,n;
double dis,bounce;
scanf("%ld %ld",&height,&n);
if(n==1)
dis=height;
else if(n==0)
dis=0;
else {
dis=height;
for(int i=2;i<=n;i++){
dis=dis+2*rebound(height,i-1);
}
}
printf("%.1f %.1f",dis,rebound(height,n));
}
double rebound(long height,long n){
if(n==1)
return 0.5*height;
else if(n==0){
double a=0;
return a;
}
else
return 0.5*rebound(height,n-1);
}
45
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
if(n%2!=0){
for(int i=1;i<=n/2+1;i++){
for(int j=1;j<=(n+1)/2-i;j++){
printf(" ");
}
for(int m=1;m<=2*i-1;m++){
printf("* ");
}
printf("\n");
}
for(int l=1;l<=n/2;l++){
for(int z=1;z<=l;z++){
printf(" ");
}
for(int k=1;k<=n-2*l;k++){
printf("* ");
}
printf("\n");
}
}
return 0;
}
46
#include<stdio.h>
main()
{
int n=10,sum=1,i;
scanf("%d",&n);
for(i=1;i<n;i++)
{
sum=sum+1;
sum=sum*2;
}
printf("%d",sum);
return 0;
}
47
#include<stdio.h>
int main()
{
int i,a[100],n;
a[1]=1,a[2]=1;
scanf("%d",&n);
i=2;
while(a[i]<n)
{
a[i+1]=a[i]+a[i-1];
i++;
}
if(i!=2)
printf("%d",i);
else
printf("1");
return 0;
}
48
# include<stdio.h>
int main()
{
int number1, number2;
int flag;
char ch;
scanf("%d", &number1);
flag = 1;
while ((ch = getchar()) != '=')
{
scanf("%d", &number2);
switch (ch)
{
case '+': number1 += number2; break;
case '-':number1 -= number2; break;
case '*':number1 *= number2; break;
case '/':
if (number2 == 0)
{
flag = 0;
break;
}
else
{
number1 /= number2; break;
}
default: flag = 0; break;
}
}
if (flag == 0)
{
printf("ERROR");
}
else
{
printf("%d", number1);
}
return 0;
}
49
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int i,j=0,sign=0;
char str[10000];
gets(str);
if(str[0]!=' ')
{
sign=1;
}
for(i=0;i<strlen(str)-1;i++)
{
if(str[i]==' '&&str[i+1]!=' ')
{
sign++;
}
}
printf("%d\n",sign);
system("pause");
return 0;
}
50
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int number[n];
for(int i=0;i<n;i++)
{
scanf("%d",&number[i]);
}
int max=number[0];
int flag=0;
for(int i=1;i<n;i++)
{
if(number[i] > max)
{
max = number[i];
flag = i;
}
else continue;
}
printf("%d %d\n",max,flag);
return 0;
}
51
#include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("%d",a[n-1]);
for(i=n-2;i>=0;i--){
printf(" %d",a[i]);
}
return 0;
}
52
#include<stdio.h>
int main()
{
int a[20], b[20], c[20];
int m, n, i, j, k=0;
scanf("%d", &m);
for(i=0; i<m; i++)
scanf("%d", &a[i]);
scanf("%d", &n);
for(i=0; i<n; i++)
scanf("%d", &b[i]);
for(i=0; i<m; i++){
for(j=0; j<n; j++){
if(a[i]==b[j])
break;
}
if(j>=n){
c[k]=a[i];
k++;
}
}
for(i=0; i<n; i++){
for(j=0; j<m; j++){
if(b[i]==a[j])
break;
}
if(j>=m){
c[k]=b[i];
k++;
}
}
printf("%d", c[0]);
for(i=1; i<k; i++){
for(j=0; j<i; j++){
if(c[i]==c[j])
break;
}
if(j>=i)
printf(" %d", c[i]);
}
return 0;
}
53
#include <stdio.h>
int main()
{
int n,i,j;
int a[10][10];
int sum;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}
sum=0;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i+j!=n-1&&j!=n-1&&i!=n-1){
sum+=a[i][j];
}
}
}
printf("%d",sum);
return 0;
}
54
#include <stdio.h>
static int m,n;
void func(int arr[][n],int m);
int main(){
scanf("%d %d",&m,&n);
int arr[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
scanf("%d",&arr[i][j]);
}
}
func(arr,m);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
return 0;
}
void func(int arr[][n],int m){
int copy[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
copy[i][(j+m)%n]=arr[i][j];
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
arr[i][j]=copy[i][j];
}
}
}
55
#include <stdio.h>
int main()
{
int y,m,d,i,a=0;
scanf("%d/%d/%d",&y,&m,&d);
if ((y%4==0&&y%100!=0)||(y%400==0))
y=1;
for(i=1;i<m;i++)
{
switch (i)
{
case 1:a+=31;break;
case 2:if(y==1)
a+=29;
else
a+=28;break;
case 3:a+=31;break;
case 4:a+=30;break;
case 5:a+=31;break;
case 6:a+=30;break;
case 7:a+=31;break;
case 8:a+=31;break;
case 9:a+=30;break;
case 10:a+=31;break;
case 11:a+=30;break;
case 12:a+=31;break;
}
}
printf("%d",a+d);
}
56
#include <stdio.h>
int main()
{
int i, index, count;
char a, ch, str[80];
scanf("%c\n", &a);
i=0;
index=-1;
count=0;
ch=getchar();
for(i=0; ch!='\n'; i++){
str[i]=ch;
count++;
ch=getchar();
}
for(i=0; i<count; i++)
if(a==str[i])
index=i;
if(index!=-1)
printf("index = %d", index);
else
printf("Not Found");
return 0;
}
57
#include <stdio.h>
#include<string.h>
int main(){
char a[81];
int i,j;
gets(a);
j=strlen(a);
for(i=j-1;i>=0;i--)
printf("%c",a[i]);
}
58
#include<stdio.h>
#define N h
int main()
{
int h;
scanf("%d",&h);
int a[N],i,j,temp;
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<N-1;i++)
{
for(j=i+1;j<N;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<N;i++)
{
if(i==0)
printf("%d",a[i]);
else printf(" %d",a[i]);
}
}
59
#include <stdio.h>
int main()
{
int n, i, x, a[1000], max;
int b[10];
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for(i=0; i<10; i++)
{
b[i] = 0;
}
for(i=0; i<n; i++)
{
if(a[i]==0)
{
b[0]++;
}
while(a[i]>0)
{
x = a[i] % 10;
a[i] /= 10;
b[x]++;
}
}
max = b[0];
for(i=1; i<10; i++)
{
if(b[i]> max)
{
max = b[i];
}
}
printf("%d:", max);
for(i=0; i<10; i++)
{
if(b[i]==max)
{
printf(" %d", i);
}
}
return 0;
}
60
#include <stdio.h>
#define N 200
int main(void)
{
int x[N][N],a,b,c[N],d=0,e;
scanf("%d",&a);
for(int i=0;i<a;++i){
e=1;
scanf("%d",&b);
for(int j=0;j<b;++j)
for(int k=0;k<b;++k){
scanf("%d",&x[j][k]);
}
for(int j=1;j<b;++j)
for(int k=0;k<j;++k){
if(x[j][k]){
e=0;
break;
}
}
if(e) c[d++]=1;
else c[d++]=0;
}
if(c[0]) printf("YES");
else printf("NO");
for(int i=1;i<d;++i){
if(c[i]) printf("\nYES");
else printf("\nNO");
}
}
61
#include <stdio.h>
int main(void)
{
int m, n, temp, sum = 0;
scanf("%d %d", &m, &n);
for(int i =0; i< m; i++)
{
for (int j = 0; j< n; j++)
{
scanf("%d", &temp);
sum += temp;
}
printf("%d\n", sum);
sum = 0;
}
return 0;
}
62
#include<stdio.h>
int main(void)
{
int matrix[6][6];
int n;
int existSaddlePoint = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
scanf("%d", &matrix[i][j]);
}
}
for (int i = 0; i < n; i++)
{
int maxRow = matrix[i][0];
int index = 0;
int flag = 1;
for (int j = 1; j < n; j++)
{
if (matrix[i][j] >= maxRow)
{
maxRow = matrix[i][j];
index = j;
}
}
for (int k = 0; k < n; k++)
{
if (matrix[k][index] < maxRow)
{
flag = 0;
break;
}
}
if (flag == 1)
{
existSaddlePoint = 1;
printf("%d %d", i, index);
break;
}
}
if (existSaddlePoint == 0)
{
printf("NONE");
}
return 0;
}
63
#include<stdio.h>
int main(){
int count=0;
char a[80];
for(int i=0;i<80;i++){
scanf("%c",&a[i]);
if(a[i]=='\n')
break;
}
for(int i=0;i<80;i++){
if(a[i]>'A'&&a[i]<='Z'){
if(a[i]!='E'&&a[i]!='I'&&a[i]!='O'&&a[i]!='U'){
count++;
}
}
if(a[i]=='\n')
break;
}
printf("%d\n",count);
return 0;
}
64
#include<stdio.h>
#include<ctype.h>
int main(void) {
char ch;
while ((ch = getchar()) != '\n') {
if (isupper(ch)) {
printf("%c", 155 - ch);
}
else
printf("%c", ch);
}
printf("\n");
return 0;
}
65
#include <stdio.h>
int main()
{
char ch;
int a[100] = { 0 };
int isminus = 0;
int cnt = -1;
while ((ch = getchar()) != '#')
{
if (ch == '-' && cnt == -1)
isminus = 1;
if (ch >= '0' && ch <= '9')
a[++cnt] = ch - '0';
if (ch >= 'a' && ch <= 'f')
a[++cnt] = ch - 'a' + 10;
if (ch >= 'A' && ch <= 'F')
a[++cnt] = ch - 'A' + 10;
}
int sum = 0;
int ret = 1;
int i;
for (i = cnt; i >= 0; i--)
{
sum += ret * a[i];
ret *= 16;
}
if (isminus && cnt!=-1)
printf("-");
printf("%d", sum);
return 0;
}
66
#include<stdio.h>
#include<string.h>
int main()
{
char a[5][81];
char b[1][81];
for(int i=0;i<5;i++){
scanf("%s",a[i]);
}
for(int i=0;i<4;i++){
for(int j=i+1;j<5;j++){
if(strcmp(a[i],a[j])>0){
strcpy(b[0],a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],b[0]);
}
}
}
printf("After sorted:\n");
for(int i=0;i<5;i++){
printf("%s\n",a[i]);
}
return 0;
}
67
#include<stdio.h>
#include<stdlib.h>
void minmaxava(int *arr,int *da,int *xiao,int *ava,int n);
int main(){
int N = 0;
int i;
int *pa=(int*)malloc(sizeof(int)*N);
int average, max, min;
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&pa[i]);
minmaxava(pa,&max,&min,&average,N);
printf("average = %d\n",average);
printf("max = %d\n",max);
printf("min = %d\n",min);
return 0;
}
void minmaxava(int *arr,int *da,int *xiao,int *ava,int n){
int sum=0;int i;
*da=*xiao=arr[0];
for(i=0;i<n;i++){
if(arr[i]>*da)
*da=arr[i];
if(arr[i]<*xiao)
*xiao=arr[i];
}
for(i=0;i<n;i++){
sum=sum+arr[i];
}
*ava=sum/n;
}
68
#include<stdio.h>
int main()
{
int hh, mm, ss;
scanf("%d:%d:%d",&hh,&mm,&ss);
int n;
scanf("%d",&n);
ss = ss + n;
mm += (ss - ss%60) > 0, ss %= 60;
hh += (mm - mm%60) > 0, mm %= 60;
hh %= 24;
printf("%02d:%02d:%02d",hh,mm,ss);
return 0;
}
69
#include<stdio.h>
#include<math.h>
int main(void)
{
double x1, y1, x2, y2;
double x, y;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
x = x1 + x2;
y = y1 + y2;
if (fabs(x) < 0.05)
{
x = fabs(x);
}
if (fabs(y) < 0.05)
{
y = fabs(y);
}
printf("(%.1f, %.1f)\n", x, y);
return 0;
}
70
#include<stdio.h>
typedef struct book{
double price;
char name[31];
} B;
int main(){
int n,flag=0;
scanf("%d",&n);
B maxb,minb;
maxb.price=minb.price=0;
while(n--){
getchar();
B bb;
gets(bb.name);
scanf("%lf",&bb.price);
if(!flag){
flag=1;
minb=bb;
}
if(maxb.price<bb.price)
maxb=bb;
if(minb.price>bb.price)
minb=bb;
}
printf("%.2lf, %s\n%.2lf, %s",maxb.price,maxb.name,minb.price,minb.name);
return 0;
}
71
#include<stdio.h>
struct ren
{
char name[10];
int year;
char tel[17];
};
int main()
{
int n;
scanf("%d",&n);
struct ren temp;
struct ren fri[n];
for(int i=0;i<n;i++)
{
scanf("%s %d %s",&fri[i].name,&fri[i].year,&fri[i].tel);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(fri[i].year>fri[j].year)
{
temp=fri[i];
fri[i]=fri[j];
fri[j]=temp;
}
}
}
for(int i=0;i<n;i++)
{
printf("%s %d %s\n",fri[i].name,fri[i].year,fri[i].tel);
}
return 0;
}
|