SWUST学校OJ

1002,水仙花数,题目链接:https://www.oj.swust.edu.cn/problem/show/1002

#include 
#include 
int main()
{
	int m,n,i,a,b,c,d,e=0;
	int f[10],j=0;
	while(scanf("%d %d",&m,&n)!=EOF)
	{
		j=0;
		if(m==0&&n==0)
			break;
		else
		{
			for(i=m; i<=n; i++)
			{
				a=i/100;
				b=i%100/10;
				c=i%100%10;
				d=a*a*a+b*b*b+c*c*c;
				if(d==i)
				{
					f[j]=i;
					j++;

				}//数据放到数组中

			}
			if(j==0)
				printf("no\n");
			else
			{
				for(i=0; i

1003, 你来做裁判,题目链接:https://www.oj.swust.edu.cn/problem/show/1003

#include 
#include 
int main()
{
    int N,num[1001],t=0,i,j;
    char ID[1001][40],c[40];
    scanf("%d",&N);
    getchar();
    for(i=0;inum[i+1])
        {
            t=num[i];
            num[i]=num[i+1];
            num[i+1]=t;
            strcpy(c,ID[i]);
            strcpy(ID[i],ID[i+1]);
            strcpy(ID[i+1],c);
           }
       }
       for(i=0;i

1004,分花生游戏博弈论,题目链接:https://www.oj.swust.edu.cn/problem/show/1004

#include
int main()
{  
    int m,n;  
    while(scanf("%d %d",&m,&n)!=EOF)
    {   
     
    if(m%5==0||m%5==4||m%5==1||n%5==1||n%5==4||n%5==0)//找出谭顺华老师的必胜数字。   
    printf("No\n");  
     
    else   
    printf("Yes\n");
     
    } 
    return 0;
}

1007,钻石问题,题目链接:https://www.oj.swust.edu.cn/problem/show/1007

#include 
int main()
{
    int v,e,mian;
    while(scanf("%d %d",&v,&e)!=EOF)//m为顶点数 n为棱数
    {
        mian=2+v-e;
        printf("%d\n",mian);
     } 
    return 0;
 }

1008,素数问题,题目链接:https://www.oj.swust.edu.cn/problem/show/1008

#include 
#include 
#include 
int main()
{
    int t;
    long int n;
    unsigned long long m,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%llu",&m);
        if(m==1)
        printf("No\n");
        else
        {
        for(i=2;i*i

1009,进制转化,题目链接:https://www.oj.swust.edu.cn/problem/show/1009

暴力解法(来自某队友的思路)

#include 
#include 
  
int main()
{
    int N,R,i,j,a[100];
    while(scanf("%d%d",&N,&R)!=EOF)
    {
        i=0;
        if(N==0&&R==0)
        {
            break;
        }
        else if(N==0&&R!=0)
        {
            printf("0");
        }
        if(R<=9)
        {
            while(N)
            {
                if(N>0)
                {
                    a[i]=N%R;
                    i++;
                    N/=R;
                }
                else
                {
                    printf("-");
                    N*=-1;
                    a[i]=N%R;
                    i++;
                    N/=R;
                }
            }
            j=sizeof(a);
            for(j=i-1; j>=0; j--)
            {
                printf("%d",a[j]);
            }
            printf("\n");
        }
        else if(R>9)
        {
            while(N)
            {
                a[i]=N%R;
                i++;
                N/=R;
            }
            for(j=i-1; j>=0; j--)
            {
                switch(a[j])
                {
                case 10:
                    printf("A");
                    break;
                case 11:
                    printf("B");
                    break;
                case 12:
                    printf("C");
                    break;
                case 13:
                    printf("D");
                    break;
                case 14:
                    printf("E");
                    break;
                case 15:
                    printf("F");
                    break;
                default:
                    printf("%d",a[j]);
                    break;
                }
                if(j==0)
                {
                    printf("\n");
                }
            }
        }
    }
    return 0;
}

1012: A Simple Task题目链接:https://www.oj.swust.edu.cn/problem/show/1012

#include 
#include 
int main()
{
    int n,i=0,len,j;
    char m[100][60];
    while(scanf("%s",m[i])!=EOF)
    {
        if(m[i][0]=='#')
        break;
        else
        len=strlen(m[i]);
        printf("%c",m[i][0]);
        for(j=1;j

1013: Part-time Job     题目链接:https://www.oj.swust.edu.cn/problem/show/1013   

#include 
int main()
{
    int m,n,p;
    while(scanf("%d %d %d",&m,&n,&p)!=EOF)
    {
        if(m==0&&n==0&&p==0)
        break;
        else if(m>n*p) 
        printf("%d\n",m);
        else
        printf("%d\n",n*p);
    }
    return 0;
}

1014,两数相加的输入输出,题目链接:https://www.oj.swust.edu.cn/problem/show/1014

#include"stdio.h"   
int main()
{
    int a,b;
    while(scanf("%d %d", &a,&b) != EOF) ///EOF:end of file  文件结束标志
    {
        if(a==0 && b==0)
            break;
        printf("%d\n", a+b);
    }
    return 0;
}

1015,两数相加的输入输出,题目链接:https://www.oj.swust.edu.cn/problem/show/1015

#include"stdio.h" 
int main()
{
    int testcases;
    int n,x,sum;
    scanf("%d", &testcases);
    while(testcases--)
    {
        scanf("%d", &n);
        sum = 0;
        while(n--)
        {
            scanf("%d", &x);
            sum += x;
        }
        printf("%d\n", sum);
        printf("\n");
    }
    return 0;
}

1017, 牛人的题目,位运算,题目链接:https://www.oj.swust.edu.cn/problem/show/1017

#include 
#include 
 
int main()
{
    int a, i = 0, N, b;
    while(scanf("%d", &N) != EOF)
    {
        if(!N)
        break;
        i = 0, b = 0;
        for(i = 0; i < N; i++)
        {
            scanf("%d", &a);
            b = b^a;
        }
        printf("%d\n", b);
    }
 
}
#include 
using namespace std;
int main()
{
    int ans = 0;
    int k = 0, n = 0;
    while(cin>>n)
    {
        ans = 0, k = 0;
        if( !n)
        break;
        while(n--)
        {
            cin >> k;
            ans = ans^k;
        }
        printf("%d\n",ans);
    }
}
#include 
int main()
{
    int ans = 0;
    int a = 0, n = 0, x = 0;
    while(scanf("%d",&n) != EOF)
    {
        x = 0, a = 0;
        if(n == 0)
        break;
        while(n--)
        {
            scanf("%d",&a);
            x = x^a;
        }
        printf("%d\n",x);
    }
}

1020,猴子吃桃,题目链接:https://www.oj.swust.edu.cn/problem/show/1020

#include 
int main()
{
    int n,a,i,N;
    while((scanf("%d",&n))!=EOF)
    {
        if(n==0)
        break; 
        N=1;
    for(i=1;i

1021,简单的排序算法,题目链接:

https://www.oj.swust.edu.cn/problem/show/1021

 

#include 
int main()
{
    int n,a[1000][3],i,j,t;
    scanf("%d",&n);
    for(i=0;i

1022: 分花生游戏系列之2 (简单博弈论)

https://www.oj.swust.edu.cn/problem/show/1022

#include 
int main()
{
    int T,last;
    long long m;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&m);
        /*if(m==6)
        printf("Mr Tan win.\n");
        else
        {
         
        last=m%10;
        if(last>5&&last<=10)
        printf("Mr Yang win.\n");
        else
        printf("Mr Tan win.\n");
         
        }*/
        if(m%6==0)
        printf("Mr Yang win.\n");
        else
        printf("Mr Tan win.\n");
        }
    return 0; 
}

1024: 排序  https://www.oj.swust.edu.cn/problem/show/1024

#include 
#include 
int main()
{
    long long a[100000],n,t,j;  
    int i;
    while((scanf("%lld",&n))!=EOF) //while((scanf("%d",&n))!=EOF)
    {
        if(n==0)
        break;
        for(i=0;ia[i+1])
            {
                t=a[i];
                a[i]=a[i+1];
                a[i+1]=t;
              }//冒泡排序法 
           }
           for(i=0;i

1031: Euclid's Game(博弈论)

https://www.oj.swust.edu.cn/problem/show/1031

#include
using namespace std;
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)==2&&(a+b)!=0)
    {
        int f=1;
        for(;;)
        {
            if(a>b)
            swap(a,b);//aa)break;
            b-=a;
            f=!f;
        }
        if(f == 1)
        printf("Stan wins\n");
        else
        printf("Ollie wins\n");
    }
}

1044: 陶陶摘苹果 https://www.oj.swust.edu.cn/problem/show/1044

#include 
int main()
{
    int i,n,sum=0;
    int a[10];
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);//十颗树的高度
    scanf("%d",&n);
    for(i=0;i<10;i++)
    {
        if(a[i]<=n+30)
        sum+=1;//记录能摘到的苹果数 
     }
     printf("%d",sum);
     return 0; 

 

你可能感兴趣的:(课程学习)