SPOJ Problem 2157:Anti-Blot System

已知一个加法的等式,将被污点覆盖的地方补全。。

实际上没啥要注意的。。

#include<cstdio>
#include<cstring>
char s[4][20],r;
int a,b,c,i,j,l;
int p,n;
int main(){
    scanf("%d",&n);
    while(n--){
        scanf("%s + %s = %s",s[1],s[2],s[3]);
        p=a=b=c=0;
        for (i=0;i<strlen(s[1]);i++){
            if (s[1][i]==‘m‘){p=1;break;}
        }
        if (!p)
            for (i=0;i<strlen(s[2]);i++){
                if (s[2][i]==‘m‘){p=2;break;}
            }
        if (!p)
            p=3;
        if (p!=1)for (i=0;i<strlen(s[1]);i++)
            a=a*10+s[1][i]-48;
        if (p!=2)for (i=0;i<strlen(s[2]);i++)
            b=b*10+s[2][i]-48;
        if (p!=3)for (i=0;i<strlen(s[3]);i++)
            c=c*10+s[3][i]-48;
        if(p==1)a=c-b;
        if(p==2)b=c-a;
        if(p==3)c=a+b;
        printf("%d + %d = %d\n",a,b,c);
    }
}
时间: 2024-11-03 05:33:22

SPOJ Problem 2157:Anti-Blot System的相关文章

素数筛法--SPOJ Problem 2 Prime Generator

质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单,看它是否能被2到sqrt(N)之间的整数整除即可. def isPrime(n): if n%2==0: return False for i in xrange(3,int(math.sqrt(n)+1),2): if n%i==0: return False return True 不过要找出1

SPOJ Problem 7974:What&#39;s Next

求数列下一项,啥都不说了,贡献了N多WA... #include<cstdio> int main(){ int a,b,c; while(scanf("%d%d%d",&a,&b,&c)&&(a||b||c)){ if (b*2==c+a&&b!=a) printf("AP %d\n",2*c-b); else printf("GP %d\n",c*c/b); } return

SPOJ Problem 2: Prime Generator

嗯..在SPOJ上刷的第二题. 一开始不知道哪错了,后来发现i出现了两遍.. 因为m<10^9,所以用素数筛筛32000以内的数,开一个4000的数组存储就行.然后再从n开始用素数筛,总之效率还行. 代码如下: //0.01s 3.2M #include<cstdio> #include<cstring> #include<cmath> int n,i,j,t,m,k,tot; int a[100005],b[4000]; int prime[40000]; in

SPOJ Problem 9948:Will it ever stop

如题..http://www.spoj.com/problems/WILLITST/ #include<cstdio> long long n; int main(){ scanf("%lld",&n); while(n>1){ if (n==3||n==6){printf("NIE\n");return 0;} if (n&1)n=(n+1)/2*3;else n>>=1; } printf("TAK\n&q

SPOJ Problem 302:Count on Cantor

题目不复述了,自己看吧.http://www.spoj.com/problems/CANTON/一如既往的暴力.. #include<cstdio> int n,i,j,s,ans; int main(){ scanf("%d",&n); while(n--){ scanf("%d",&s); printf("TERM %d IS ",s); for (i=1;s>i;i++){ s-=i; } if (i&am

SPOJ Problem:A Game with Numbers

突然就看到SPOJ升级了,让我好不适应.. 这一一道博弈论的题目,可以先前面暴力一下,易得小于十的为必胜态,十的时候必败,然后11到19又必胜,而且发现只要各位为零且这个数不为零就必败. 再依次验证上百,上千的数.. #include<cstdio> #include<cstring> int n; int main(){ scanf("%d",&n); if (n%10==0&&n!=0)printf("2\n");

SPOJ Problem 379:Ambiguous Permutations

http://www.spoj.com/problems/PERMUT2/ 如题.. #include<cstdio> #include<cstring> int n,i,j; int a[100005]; int main(){ while(scanf("%d",&n)&&n){ for (i=1;i<=n;i++){ scanf("%d",&a[i]); } for (i=1;i<=n;i++)

SPOJ Problem 2727:Army Strength

题目在此  http://www.spoj.com/problems/ARMY/ 总体来说就是求最大值.. #include<cstdio> #include<cstring> int x,n,t,i,a,b; int max,pos; int main(){ scanf("%d",&t); while(t--){ scanf("%d%d",&a,&b); max=0; for (i=1;i<=a;i++){ s

SPOJ Problem:He is offside!

http://www.spoj.com/problems/OFFSIDE/ 阅读题.. #include<cstdio> #include<cstring> int x,a,b,c,n,m,i; int main(){ while(scanf("%d%d",&n,&m)&&(n+m)){ a=b=c=100000; for (i=1;i<=n;i++){ scanf("%d",&x); if (x