PTA之奥特曼拯救世界

函数题:
1.
char to_grade(int score)
{
char grade;
if((score<0)||(score>100)){
grade=’ ‘;
}else if(score>=95){
grade=‘A’;
}else if(score>=85){
grade=‘B’;
}else if(score>=70){
grade=‘C’;
}else if(score>=60){
grade=‘D’;
}else if(score<60){
grade=‘E’;
}
return grade;
}
2.
int is_leap(int year)
{
int is_leap;
if((year%4000)||(year%100!=0)&&(year%40)){
is_leap=1;
}else{
is_leap=0;
}
return is_leap;
}
3.
void input_point(Point * a, Point * b)
{
scanf("%lf %lf",&a->x,&a->y);
scanf("%lf %lf",&b->x,&b->y);
}
Point middle(Point a, Point b)
{
Point m;
m.x=(a.x+b.x)/2;
m.y=(a.y+b.y)/2;
return m;
}
4.
Date to_date(int day_of_year)
{
Date date={1, 1};
int days[12]={
31,28,31,30,31,30,31,31,30,31,30,31
};
date.day=day_of_year;
while(date.day>days[date.month-1]){
date.day-=days[date.month-1];
date.month++;
}
return date;
}
5.
6.
void input_upper_string(char * str, int n)
{
char ch;
int i;
for(i=0;i<n-1;i++){
scanf("%c",&ch);
if((ch>=‘a’)&&(ch<=‘z’)){
ch=ch-(‘a’-‘A’);
}
if(ch==’\n’){
break;
}else{
str[i]=ch;
}
}
str[i]=’\0’;
}
编程题:
1.
#include <stdio.h>
int main()
{
int a;
int b;
scanf("%d %d", &a, &b);
printf("%d", a + b);
return 0;
}
2.
#include <stdio.h>

int main(){
int a = 12;
int b = 34;
int c = 56;
int num;
num = a + b + c;
printf("%d + %d + %d = %d",a,b,c,num);
}
3.
#include <stdio.h>

int main(){
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
int num = a + b + c;
printf("%d + %d + %d = %d",a,b,c,num);

}
4.
#include <stdio.h>
int main(){
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a == b){
printf(“yes”);
}else{
printf(“no”);
}

}
5.
#include <stdio.h>

int main(){
char a;
scanf("%c",&a);
printf("%d",a);
}
6.
#include <stdio.h>

int main(){
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a>b){
printf("%d",a);
}else{
printf("%d",b);
}
}
7.
#include <stdio.h>

int main(){
int a,b,c,num,max;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);

if (a > b){
    max = b;
}else {
    max = a; 
}

if (max > c ){
    num = c;
}else {
    num = max;
}

printf("%d",num);

}
8.

#include <stdio.h>
int main(void){
int a;
scanf("%d",&a);
switch (a){
case 0:printf(“SUN”); break;
case 1:printf(“MON”); break;
case 2:printf(“TUE”); break;
case 3:printf(“WED”); break;
case 4:printf(“THU”); break;
case 5:printf(“FRI”); break;
case 6:printf(“SAT”); break;
default:printf(“Error”);
}
return 0;

}
9.
#include <stdio.h>
int main(){
int a;
scanf("%d",&a);
if (100 >= a && a >= 95){
printf(“A”);
}else if (95 > a && a>= 85){
printf(“B”);
}else if (85 >= a && a >= 70){
printf(“C”);
}else if (70 >= a && a >= 60){
printf(“D”);
}else if (60 > a && a >= 0){
printf(“E”);
}else {
printf(“Error”);
}
}
10.
#include <stdio.h>
int main (){
int a,b;
scanf("%d",&a);
b = a % 2;
if(b == 0){
printf(“even”);
}else{
printf(“odd”);
}
}
11.
#include <stdio.h>
int main(){
int a;
scanf("%d",&a);
if(a % 100 == 0 && a % 400 == 0){
printf(“leap”);
}else if (a % 100 != 0 && a % 4 == 0){
printf(“leap”);
}else{
printf(“common”);
}
}
12.
#include <stdio.h>

void main()
{
char a;
scanf("%c",&a);

if(a <= 91 && a >=65)       
{
	a = a +32;   
	printf("%c",a);

}
else if (a <=123 && a>=97)
{
	a = a-32;   
	printf("%c",a);
}else {
    printf("error");
}

}
13.
#include <stdio.h>
int main()
{ int a;
int b;
int c;
scanf("%d",&b);
while(a<b)
{a=a+1;
c=2*a-1;
printf("%d\n",c);
}
return 0;
}
14.
#include <stdio.h>
int main(){
int a,b;
scanf("%d",&a);
for(b = 0; b <= a; b++){
if(b % 2 == 0 || b % 3 == 0 || b % 5 == 0){
continue;
}else{
printf("%d\40",b);
}
}
}
15.
#include <stdio.h>
int main(){
int a,b,c;
c = 0;
scanf("%d",&a);
for(b = 0;b <= a; b++){
c += b;
}
printf("%d",c);
}

#include <stdio.h>
int main(){
int a,b,c;
c = 1;
scanf("%d",&a);
for(b = 1;b <= a;b++){
c *= b;
}
printf("%d",c);
}

#include <stdio.h>
int main(){
int a,b;
long long c = 1;
scanf("%d",&a);
for(b = 1;b <= a;b++){
c *= b;
}
printf("%lld",c);
}
18.
#include <stdio.h>
void main(){
int i,n;
scanf("%d",&n);
for(i=2;i<=n-1;i++){
if(n%i==0){
break;
}
}
if(i>=n){
printf(“prime number”);
}
else{
printf(“composite number”);
}
}
19.

#include<stdio.h>
int main()
{
int a,b,head,leg;
scanf("%d%d",&head,&leg);
a=(4*head-leg)/2;
b=head-a;
if(leg % 2==1 || a<0 || b<0){

printf("Error"); }

else{
printf("%d %d\n",a,b); }
return 0;
}
20.
#include <stdio.h>

int main(){
int a;
scanf("%d",&a);
printf("%o\n",a);
printf("%X",a);

}

#include <stdio.h>

int main(){
int a;
scanf("%o",&a);
printf("%d\n",a);
printf("%X",a);

}
22.
#include <stdio.h>

int main(){
int a;
scanf("%X",&a);
printf("%o\n",a);
printf("%d",a);

}
23.
#include <stdio.h>

int main(){
int a,b,c,max1,max2;
scanf("%d%d%d",&a,&b,&c);
max1 = a > b? a:b;
max2 = max1 > c ? max1 : c;
if(a + b > max2 && a + c > max2 && b + c > max2){
printf(“yes”);
}else{
printf(“no”);
}
}
24.
#include <stdio.h>

int main(){
int a,b,c,max1,max2;
scanf("%d%d%d",&a,&b,&c);
max1 = a > b? a:b;
max2 = max1 > c ? max1 : c;
if(a * a + b * b == max2 * max2 || a * a + c * c == max2 * max2 || b * b + c * c == max2 * max2){
printf(“yes”);
}else{
printf(“no”);
}
}
25.
#include <stdio.h>

int main(){
char a;
scanf("%c",&a);
printf("%d\40",a);
printf("%XH\40",a);
if (a >= 97 && a <=122){
printf(“lowercase”);
}else if (a >=65 && a <= 90){
printf(“uppercase”);
}else if((a>=‘0’) && (a<=‘9’)){
printf(“digital”);
}else{
printf(“other”);
}
}
26.
#include<stdio.h>
int main()
{
int a;
int b;
int c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if((a+b+c)/3>=80&&((a>=90)||(b>=90)||(c>=90))){
printf(“excellent”);
}else if((a>=75)&&(b>=75)&&(c>=75)){
printf(“good”);
}else if(((a+b+c)/3>=60)&&((a>=60)&&(b>=60)||(a>=60)&&(c>=60)||(c>=60)&&(b>=60))){
printf(“pass”);
}else{
printf(“fail”);
}
return 0;
}
27.
#include <stdio.h>

int main(){
int a,b,c;
long long int e = 1;
long long int sum = 0;
scanf("%d",&a);
for(b = 1 ; b <= a; b++){

	for(c = 1;c <= b;c++){
		e = c * e;
		/*
		1 = 1 * 1
		1 = 1 * 2 
		2 = 2 * 3
		6 = 6 * 4
		
		*/
	}
	sum += e;
	e = 1;
}
printf("%lld",sum);

}
28.
#include<stdio.h>
int main()
{
int n;
long long x=0;
long long y=1;
long long z;
int i=2;
scanf("%d",&n);
printf("%lld",x);
if(n>=2){
printf(" %lld",y);
}
for(i=2;i<n;i++){
z=x+y;
printf(" %lld",z);
x=y;
y=z;
}
return 0;
}
29.
#include<stdio.h>
int main()
{
double a,b,c;
scanf("%lf",&a);
b=a-1600;
if(b>10000){
c=1625+(b-10000)*0.3;
}else if(b>5000){
c=625+(b-5000)*0.2;
}else if(b>2000){
c=175+(b-2000)*0.15;
}else if(b>500){
c=25+(b-500)0.1;
}else if(b>0){
c=b
0.05;
}else{
c=0;
}
printf("%.2f",c);
return 0;
}
30.
#include <stdio.h>

int main(){

int a,i,j;
scanf("%d",&a);
for(i = 1;i<= a;i++){
	for(j = 1;j <= i; j++){
		printf("%dX%d=%d",j,i,i*j);
	printf("\t");
	}
	printf("\n");
}

}
31.
#include <stdio.h>

int main(){

int a,ge,shi,bai,sum;
for(a=2;a<=999;a++){
ge = (a % 10);
shi =(a / 10 % 10);
bai =(a / 100);
sum  =  ge*ge*ge + shi*shi*shi + bai*bai*bai;

if(sum == a ){
	printf("%d\n",a);
}

}	

}
32.
#include <stdio.h>
int main(){
long long a,a1,b,b1,tmp,gcd,lcm;
scanf("%lld %lld",&a,&b);
a1 = a;
b1 = b;
if(a1 < b1) {
tmp = b1;
b1 = a1;
a1 = tmp;
}
while(a1 % b1 != 0){
tmp = a1 % b1;
a1 = b1;
b1 = tmp;
}
gcd = b1;
a1 = a;
b1 = b;
lcm = (a1 * b1) / gcd;
printf("%lld\n%lld",gcd,lcm);
return 0;
}
33.
#include<stdio.h>
int main()
{
char l;
int i;
scanf("%c",&l);
scanf("%d",&i);
if((l>=65)&&(l<=90)){
for(i=0;i<26;i++){
printf("%c",65+(l-65+i)%26);
}
}else if((l>=97)&&(l<=122)){
for(i=0;i<26;i++){
printf("%c",97+(l-97+i)%26);
}
}else{
printf(“error”);
}
return 0;
}
34.
#include<stdio.h>
int main()
{
int n;
int i;
int sum=0;
scanf("%d",&n);
for(i=1;i<n;i++){
if(n%i0){
sum+=i;
}
}
if(sum
n){
printf(“yes”);
}else{
printf(“no”);
}
return 0;
}
35.
#include<stdio.h>
int main()
{
int n;
int counter=0;
scanf("%d",&n);
while(n>=1) {
if(n%21){
counter++;
}
n /=2;
}
printf("%d",counter);
return 0;
}
36.
#include <stdio.h>
int main()
{
int n;
int i=2;
scanf("%d", &n);
while(i<n){
if(n%i
0){
n /=i;
if(n>1){
printf("%d “, i);
continue;
}
if(n==1){
printf(”%d",i);
}
}
i++;
}
if(i>=n){
printf("%d", n);
}
return 0;
}
37.

#define N 10
int main()
{
char a[N];
int i;
for(i=0;i<N;i++){
scanf("%c",&a[i]);
if(a[i]==’\n’){
break;
}
}
while(–i>=0){
printf("%c",a[i]);
}
return 0;
}
38.
#include<stdio.h>
#define N 100
int main()
{
int man[N]={0};
int n;
int k;
int counter=0;
int out=0;
int i=0;
scanf("%d%d",&n,&k);
while(out<n){
if(man[i]0){
counter++;
}
if(counter
k){
man[i]=1;
out++;
counter=0;
printf("%d\n",i+1,out);
}
i=(i+1)%n;
}
return 0;
}
39.
#include<stdio.h>
int main()
{
int m,n,a1,a2,a3,b1,b2,b3;
int k=0;
while(scanf("%d %d",&m,&n)||m,n){
a1=m%10;
a2=m/10%10;
a3=m/100;
b1=n%10;
b2=n/10%10;
b3=n/100;
if(a1+b1>=10){
k++;
a2++;
}
if(a2+b2>=10){
k++;
a3++;
}
if(a3+b3>=10){
k++;
}
printf("%d\n",k);
k=0;
}
return 0;
}
40.
#include<stdio.h>
int main()
{
int k,x,y,n;
scanf("%d",&n);
while(n–){
scanf("%d",&k);
for(x=k+1;x<=2k;x++){
if((x
k)%(x-k)==0){
y=(x*k)/(x-k);
printf(“1/%d=1/%d+1/%d\n”,k,y,x);
}
}
}
return 0;
}
41.
42.
#include<stdio.h>
#include<string.h>
int main()
{
int judge[300];
char originally[10005];
char detele[10005];
while(gets(originally))
{
int i;
gets(detele);
for(i=0;i<strlen(detele);++i)
{
judge[detele[i]]=1;
}
for(i=0;i<strlen(originally);++i)
{
if(judge[originally[i]]!=1)
printf("%c",originally[i]);
}
putchar(’\n’);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值