SUST2017迎新赛
1.先说几句话
哈喽,欢迎17级的学弟学妹们来到陕科大生活和学习~
齐老师让我们现在就帖下这次的代码,方便大家在暑假的学习。希望大家在编程的学习中勇于提问,但是有个前提,一定要先经过自己的思考和相关查阅。只有这样,才能让你的提问变得有意义,对自己的学习有帮助,也能节省被提问人的时间。不懂的话就在评论里问,说明题号并尽量的将问题叙述清楚。
感谢一同提供代码的猪熊山。
2.开始了。
A
#include<stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
B
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
printf("%d\n",a+b);
}
return 0;
}
C
#include<stdio.h>
int main(){
int n,m,i,sum;
while(scanf("%d",&m)!=EOF){
sum=0;
for(i=1;i<=m;i++){
sum+=i;
}
printf("%d\n\n",sum);
}
return 0;
}
D
#include<stdio.h>
int main(){
int a,b;
while(scanf("%d %d",&a,&b)!=EOF)
printf("%d\n",a+b);
return 0;
}
E
#include<stdio.h>
int main(){
int a,b,num;
scanf("%d",&num);
while(num--){
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
}
return 0;
}
F
#include<stdio.h>
int main(){
int a,b;
while(scanf("%d %d",&a,&b)){
if(a==0 && b==0){
return 0;
}
printf("%d\n",a+b);
}
return 0;
}
G
#include <stdio.h>
#include <string.h>
int main()
{
char a;
int b,i,j,k=0;
while((a=getchar())!='@')
{
++k;
getchar();
scanf("%d",&b);
getchar();
if(k!=1)
printf("\n");
for(i=1;i<b;i++)
{
for(j=1;j<=b+(i-1);j++)
{
if(j==b-(i-1)||j==b+(i-1))
printf("%c",a);
else
printf(" ");
}
printf("\n");
}
for(i=0;i<2*b-1;i++)
printf("%c",a);
printf("\n");
}
return 0;
}
H
#include<stdio.h>
long long shulie(int n){
int i;
long long a[100] = { 0 };
a[1] = 1, a[2] = 1;
for ( i = 3; i <= n; i++)
a[i] = a[i - 1] + a[i - 2];
return a[n];
}
int main(){
int n;
scanf("%d",&n);
while (n--){
int a, b;
scanf("%d%d",&a,&b);
printf("%lld\n", shulie(b - a + 1));
}
return 0;
}
I
#include<stdlib.h>
#include<stdio.h>
int main(){
int fun(int i);
int a,b,sum=0,i,flag,ht;
while(~scanf("%d %d",&a,&b)){
ht=0; flag=0;
for(i=a;i<=b;i++){
sum=fun(i%10)+fun(i/10%10)+fun(i/10/10);
if(sum==i && flag==0){
printf("%d",sum);
flag=1;
ht=1;
}else if(sum==i && flag==1) {
printf(" %d",sum);
ht=1;
}
}
if(ht==0){
printf("no\n");
}else printf("\n");
}
return 0;
}
int fun(int i){
return i*i*i;
}
J
#include<stdio.h>
int a[40][40];
int main(){
int n;
while (scanf("%d", &n) != EOF){
for (int i = 0; i < n; i++){
a[i][0] = 1; a[i][i] = 1;
}
for (int j = 2; j < n; j++){
for (int k = 1; k <= j; k++){
a[j][k] = a[j - 1][k - 1] + a[j - 1][k];
}
}
for (int j = 0; j < n; j++){
for (int k = 0; k <= j; k++){
if(k<j) printf("%d ",a[j][k]);
else printf("%d", a[j][k]);
} printf("\n");
}
printf("\n");
}
return 0;
}
K
#include<stdio.h>
#include<math.h>
int main() {
int a[50][50];
double x,y,aver1[50],aver2[50],sum;
int i,j,n,m,count,p;
while(~scanf("%d%d",&n,&m)) {
count=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(i=0;i<n;i++) {
sum=0;
for(j=0;j<m;j++)
sum+=a[i][j];
aver1[i]=sum/m;
}
for(j=0;j<m;j++) {
sum=0;
for(i=0;i<n;i++)
sum+=a[i][j];
aver2[j]=sum/n;
}
for(i=0;i<n;i++) {
p=1;
for(j=0;j<m;j++)
if(a[i][j]<aver2[j]) { p=0; break; }
if(p) count++;
}
for(i=0;i<n-1;i++)
printf("%.2lf ",aver1[i]);
printf("%.2lf\n",aver1[i]);
for(i=0;i<m-1;i++) printf("%.2lf ",aver2[i]);
printf("%.2lf\n",aver2[i]); printf("%d\n\n",count);
}
return 0;
}
L
#include<stdio.h>
int main(){
int num=1,count=0,i;
int cat[101]={0};
while(scanf("%d",&num),num){
for(i=0;i<num;i++){
scanf("%d",&cat[i]);
}
for(i=0;i<num;i++){
while(cat[i]!=0){
if(cat[i]>=100){
cat[i]-=100;
count++;
}else if(cat[i]>=50){
cat[i]-=50;
count++;
}else if(cat[i]>=10){
cat[i]-=10;
count++;
}else if(cat[i]>=5){
cat[i]-=5;
count++;
}else if(cat[i]>=2){
cat[i]-=2;
count++;
}else if(cat[i]>=1){
cat[i]-=1;
count++;
}
}
}
printf("%d\n",count);
count=0;
}
return 0;
}
M
#include<stdio.h>
int main(){
long long a[60];
a[1] = 1, a[2] = 2, a[3] = 3;
for (int i = 4; i <= 55; i++)
a[i] = a[i - 3] + a[i - 1];
int n;
while (scanf("%d", &n) != EOF){
if (n == 0) break;
printf("%lld\n",a[n]);
}
return 0;
}
N
#include<stdio.h>
int main() {
int a,b,c=1,i;
while((scanf("%d",&a))!=EOF){
c=1; for(i=0;i<a;i++) {
scanf("%d",&b);
if(b%2!=0) c*=b;
}
printf("%d\n",c);
}
}
O
#include<stdio.h>
#include<string.h>
int main()
{
int num;
char str[11];
scanf("%d",&num);
while(num--)
{
scanf("%s",str);
printf("6%s\n",str+6);
}
return 0;
}
P
#include<stdio.h>
int main()
{
int a, b;
int gcd(int a,int b);
while(scanf("%d %d",&a,&b)!=EOF)
{
int ans;
ans=a*b/gcd(a,b);
printf("%d\n",ans);
}
return 0;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
Q
#include<stdio.h>
int main(){
int num;
scanf("%d",&num);
while(num--){
int f,flag=0,size=0;
scanf("%d",&f);
while(f!=1)
{
if(f%2!=0)
{
flag=1;
if(size==0)
{
printf("%d",f);
size=1;
}
else printf(" %d",f);
f=f*3+1;
}
else if(f%2==0){
f=f/2;
}
}
if(flag==0){
printf("No number can be output !");
}
printf("\n");
}
return 0;
}
R
#include <stdio.h>
#include <string.h>
int main()
{
char a;
int b,i,j,k=0;
while((a=getchar())!='@')
{
++k;
getchar();
scanf("%d",&b);
getchar();
if(k!=1)
printf("\n");
for(i=1;i<b;i++)
{
for(j=1;j<=b+(i-1);j++)
{
if(j==b-(i-1)||j==b+(i-1))
printf("%c",a);
else
printf(" ");
}
printf("\n");
}
for(i=0;i<2*b-1;i++)
printf("%c",a);
printf("\n");
}
return 0;
}
S
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
while(num--)
{
int x,y,ans;
scanf("%d %d",&x,&y);
if(x==y && x>=0 && y>=0)
{
if(x%2==0)ans=2*x;
else ans=2*x-1;
printf("%d\n",ans);
}
else if(y==x-2 && x>=2)
{
if(x%2==0)ans=2*x-2;
else ans=2*x-1-2;
printf("%d\n",ans);
}
else printf("No Number\n");
}
return 0;
}
T
#include<stdio.h>
#include<math.h>
int main(){
double x1,y1,x2,y2;
while(scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2)!=EOF){
printf("%.2lf\n",sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}
return 0;
}
U
#include<stdio.h>
#define PI 3.1415927
int main(){
double i;
while(scanf("%lf",&i)!=EOF){
printf("%.3lf\n",PI*i*i*i*4.0/3.0);
}
return 0;
}
V
#include<stdio.h>
int main(){
int n,a,b,c,i;
double h[100];
while(scanf("%d",&n),n){
a=0;b=0;c=0;
for(i=0;i<n;i++){
scanf("%lf",&h[i]);
}
for(i=0;i<n;i++){
if(h[i]>0)a++;
if(h[i]==0)b++;
if(h[i]<0)c++;
}
printf("%d %d %d\n",c,b,a);
}
return 0;
}
W
#include<stdio.h>
int main(){
int fun(int n);
int n;
while(~scanf("%d",&n)){
printf("%d\n",fun(n));
}
return 0;
}
int fun(int n){
if(n==1){
return 1;
}
return (fun(--n)+1)*2;
}
X
#include<stdio.h>
int main(){
int num;
while(~scanf("%d",&num)){
if(num<0 || num>100){
printf("Score is error!\n");
}
else if(num>=90 && num<=100){
printf("A\n");
}else if(num>=80){
printf("B\n");
}else if(num>=70){
printf("C\n");
}else if(num>=60){
printf("D\n");
}else if(num>=0){
printf("E\n");
}
}
return 0;
}
Y
#include<stdio.h>
int main(){
int i,j,h,sum2=0,sum1=0,temp;
while(scanf("%d %d",&i,&j)!=EOF){
if(i>=j){
temp=i;
i=j;
j=temp;
}
for(h=i;h<=j;h++){
if(h%2==0){
sum1+=h*h;
}
else{
sum2+=h*h*h;
}
}
printf("%d %d\n",sum1,sum2);
sum1=0;
sum2=0;
}
return 0;
}
Z
#include <stdio.h>
int main(void)
{
int n;
while(scanf("%d", &n) != EOF) {
int score, sum=0, max=0, min=101, i;
for(i=1; i<=n; i++) {
scanf("%d", &score);
sum += score;
max = (score > max) ? score : max;
min = (score < min) ? score : min;
}
printf("%.2f\n", (float)(sum - max - min) / (n -2));
}
return 0;
}
6 comments
|´・ω・)ノ
你这排版排的是个锤子
我改好了
等你来学校了,我打死你
66666