首页 > 试题广场 >

A+B in Hogwarts (20)

[编程题]A+B in Hogwarts (20)
  • 热度指数:5578 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enough." Your job is to write a program to compute A+B where A and B are given in the standard form of "Galleon.Sickle.Knut" (Galleon is an integer in [0, 107 ], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).

输入描述:
Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.


输出描述:
For each test case you should output the sum of A and B in one line, with the same format as the input.
示例1

输入

3.2.1 10.16.27

输出

14.1.28
水题....
#include <cstdio>
using namespace std;

struct money
{
	int galleon, knut, sickle;
public:
	money() {}
	money(int g, int s, int k): galleon(g), knut(k), sickle(s){}
public:
	money operator+(const money &m) const{
		money s;
		s.knut = knut + m.knut;
		s.sickle = sickle + m.sickle;
		s.galleon = galleon + m.galleon;
		s.sickle += (s.knut / 29);
		s.knut = s.knut % 29;
		s.galleon += (s.sickle / 17);
		s.sickle = s.sickle % 17;
		return s;
	}
};

int main(){
	int g, s, k;
	scanf("%d.%d.%d", &g, &s, &k);
	money m1(g, s, k);
	scanf("%d.%d.%d", &g, &s, &k);
	money m2(g, s, k);
	money m = m1 + m2;
	printf("%d.%d.%d\n", m.galleon, m.sickle, m.knut);
	return 0;
}

发表于 2017-08-25 00:56:01 回复(1)
//果真我还是适合做这种题。。
#include<iostream>
#include<cstdio>
using namespace std;
int a1,b1,c1,a2,b2,c2;
int main()
{
    scanf("%d.%d.%d %d.%d.%d",&a1,&b1,&c1,&a2,&b2,&c2);
    printf("%d.%d.%d",a1+a2+(b1+b2+(c1+c2)/29)/17,(b1+b2+(c1+c2)/29)%17,(c1+c2)%29);
    return 0;
}
发表于 2020-01-10 14:45:56 回复(0)
甲级也有这样的水题?!。。。
#include<stdio.h>
using namespace std;
int main() {
    int a,b,c,d,e,f;
    scanf("%d.%d.%d %d.%d.%d",&a,&b,&c,&d,&e,&f);
    b += e + (c+f)/29;
    a += d + b/17;
    printf("%d.%d.%d\n",a,b%17,(c+f)%29); 
return 0;
}

发表于 2018-12-17 14:06:28 回复(0)
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str1=sc.next();
        String str2=sc.next();
        String[] moneys1=str1.split("\\.");
        String[] moneys2=str2.split("\\.");
        int galleon,sickle,knuts;
        knuts=Integer.valueOf(moneys1[2])+Integer.valueOf(moneys2[2]);
        int flag=0;
        if(knuts>=29){
            flag=1;
            knuts=knuts%29;
        }
        sickle=Integer.valueOf(moneys1[1])+Integer.valueOf(moneys2[1])+flag;
        flag=0;
        if(sickle>=17){
            flag=1;
            sickle=sickle%17;
        }
        galleon=Integer.valueOf(moneys1[0])+Integer.valueOf(moneys2[0])+flag;
        System.out.println(galleon+"."+sickle+"."+knuts);
    }
}

发表于 2018-10-03 17:37:14 回复(0)

/**  * 首先数据处理先读取一行字符串  * 然后进行字符串处理  * 把相应的Galleon,Sickle Knut读取出来并且读取的过程就开做加法  * 然后开始做相应的进位***作并行除数取余!  *  * */


import
java.io.*; public class Main{ public static void main(String [] args)throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int Galleon=0; int temp=1; int Sickle=0; int Knut=0; String comString=reader.readLine();// 把第一行的信息读取进来 int i=comString.length()-1; for(int j=5;j>=0;j--) { while (i >=0) { if (comString.charAt(i) == '.' || comString.charAt(i) == ' ') { temp=1; i--; break; } if(j==0||j==3) { Galleon+=(comString.charAt(i) - '0') *temp; } else if(j==1||j==4) { Sickle+=(comString.charAt(i) - '0') *temp; } else if(j==2||j==5) { Knut+=(comString.charAt(i) - '0') *temp; } i--; temp*=10; } } temp=Knut/29; Knut%=29; i=(Sickle+temp)/17; Sickle=(temp+Sickle)%17; Galleon+=i; System.out.println(Galleon+"."+Sickle+"."+Knut); } }

发表于 2018-09-27 22:11:51 回复(0)

#include <iostream>

#include <string>

using namespace std;

int main() {

    string s1, s2;

    int a[7];

    while (cin >> s1 >> s2) {

        for (int i = 0; i < 6; i++) {

            a[i] = 0;

        }

        int l1 = s1.size(), l2 = s2.size();

        int tmp = 0;

        int num = 0;

        for (int i = 0; i < l1; i++) {

            if (s1[i] >= '0'&&s1[i] <= '9') {

                tmp = tmp * 10 + s1[i] - '0';

            }

            else if (s1[i] == '.') {

                a[num] = tmp;

                num++;

                tmp = 0;

            }

        }

        a[2] = tmp;

        num++;

        tmp = 0;

        for (int i = 0; i < l2; i++) {

            if (s2[i] >= '0'&&s2[i] <= '9') {

                tmp = tmp * 10 + (s2[i] - '0');

            }

            else if (s2[i] == '.') {

                a[num++] = tmp;

                tmp = 0;

            }

        }

        a[5] = tmp;

        int carry = 0;

        int ans[3] = { 0 };

        ans[2] = (a[2] + a[5]) % 29;

        carry = (a[2] + a[5]) / 29;

        ans[1] = (a[1] + a[4] + carry) % 17;

        carry = (a[1] + a[4] + carry) / 17;

        ans[0] = a[0] + a[3] + carry;

        cout << ans[0] << '.' << ans[1] << '.' << ans[2] << endl;

    }

    return 0;

}


发表于 2018-03-10 20:56:16 回复(0)
会有大数的问题,要用long long 型
#include <stdio.h>

const int Galleon = 17 * 29;
const int Sickle = 29;

int main(){
    long long G1, S1, K1, G2, S2, K2;
    scanf("%lld.%lld.%lld %lld.%lld.%lld", &G1, &S1, &K1, &G2, &S2, &K2);
    long long sum = G1 * Galleon + S1 * Sickle + K1 + G2 * Galleon + S2 * Sickle + K2;
    printf("%lld.%lld.%lld", sum / Galleon, sum % Galleon / Sickle, sum % Sickle);
    return 0;
}

发表于 2018-03-01 12:32:33 回复(0)
import java.util.Scanner; 
public class Main{
    public static void main(String[] args) {   	
        Scanner in=new Scanner(System.in);        
        String[] s1=in.next().split("\\.");
        String[] s2=in.next().split("\\.");      
        int[] a=new int[3];
        int[] b={-1,17,29};        
        for(int i=2;i>=0;i--){        	
        	a[i]+=Integer.parseInt(s1[i]);
        	a[i]+=Integer.parseInt(s2[i]);       	
        	if(a[i]>=b[i] && b[i]>0){
        		a[i-1]++;
        		a[i]%=b[i];
        	}
        }      
        for(int i=0;i<3;i++){
        	System.out.print(a[i]);
        	if(i!=2)
        		System.out.print(".");
        }
    }
}

发表于 2017-01-22 14:47:15 回复(0)
import java.util.Scanner;
public class Main{
	private static final int[] W = {100000000,17,29};
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] a = in.next().split("\\.");
		String[] b = in.next().split("\\.");
		String[] result = new String[3];
		int f = 0;
		for(int i = 2;i>=0;i--){
			int r = Integer.parseInt(a[i])+Integer.parseInt(b[i])+f;
			f = r/W[i];
			r = r%W[i];
			result[i] = ""+r;
		}
		for(int i = 0;i<2;i++){
			System.out.print(result[i]+".");
		}
		System.out.println(result[2]);
	}
}

发表于 2016-07-23 20:03:06 回复(0)
#include<bits/stdc++.h>
using namespace std;

const int G=17*29;
const int S=29;

int main(){
	int a[2],b[2],c[2];
	scanf("%d.%d.%d %d.%d.%d",&a[0],&b[0],&c[0],&a[1],&b[1],&c[1]);
	long long x=a[0]*G+b[0]*S+c[0];
	long long y=a[1]*G+b[1]*S+c[1];
	long long z=x+y;
	cout<<z/G<<'.'<<z%G/S<<'.'<<z%S<<endl;
	return 0;
}

发表于 2022-11-05 16:24:51 回复(2)
#include <bits/stdc++.h>

using namespace std;

struct Coin
{
	int a;
	int b;
	int c;
	Coin(int a, int b, int c) : a(a), b(b), c(c) {}
};

struct Coin operator+(const struct Coin p1, const struct Coin p2)
{	
	int res_c = (p1.c + p2.c) % 29;
	int pre_c = (p1.c + p2.c) / 29;
	int res_b = (p1.b + p2.b + pre_c) % 17;
	int pre_b = (p1.b + p2.b + pre_c) / 17;
	int res_a = (p1.a + p2.a + pre_b);
	struct Coin p = { res_a, res_b, res_c };
	return p;
}

int main()
{
	int a1, b1, c1, a2, b2, c2;
	//scanf_s("%d.%d.%d %d.%d.%d", &a1, &b1, &c1, &a2, &b2, &c2);
	scanf("%d.%d.%d %d.%d.%d", &a1, &b1, &c1, &a2, &b2, &c2);
	struct Coin p1 = { a1, b1, c1 };
	struct Coin p2 = { a2, b2, c2 };
	struct Coin p3 = p1 + p2;
	printf("%d.%d.%d\n", p3.a, p3.b, p3.c);
}

发表于 2020-03-30 18:21:47 回复(0)
基本上三种思路:
1、贪心
2、模拟加减进位
3、化为最小单位,运算结果取余输出

我这里采用2

#include<iostream>
using namespace std;

int main() {
	int g1,s1,k1,g2,s2,k2,g,s,k;
	scanf("%d.%d.%d %d.%d.%d",&g1,&s1,&k1,&g2,&s2,&k2);
	g=g1+g2;
	s=s1+s2;
	k=k1+k2;
	if(k>28){
		k-=29;
		s++;
	}
	if(s>16){
		s-=17;
		g++;
	}
	cout<<g<<"."<<s<<"."<<k;
    return 0;
}


发表于 2020-01-31 21:16:58 回复(0)
x=input().strip().split(' ')
a=x[0].split('.')
b=x[1].split('.')
c=[0,0,0]
c[2]=int(a[2])+int(b[2])
if c[2]>=29:
    c[1]+=c[2]//29
    c[2]=c[2]%29
c[1]+=int(a[1])+int(b[1])
if c[1]>=17:
    c[0]+=c[1]//17
    c[1]=c[1]%17
c[0]+=int(a[0])+int(b[0])
print(c[0],c[1],c[2],sep='.')
这题很简单
发表于 2019-03-09 12:08:08 回复(0)
A,B=input().split()
A,B=list(map(int,A.split('.'))),list(map(int,B.split('.')))
res,up=[0]*3,0
Mod=[pow(10,8),17,29]
for i in range(2,-1,-1):
    res[i]=(A[i]+B[i]+up)%Mod[i]
    up=(A[i]+B[i]+up)//Mod[i]
print('.'.join(map(str,res)))
加法,简尽其洁
发表于 2018-08-31 09:30:29 回复(0)
#include<string.h>
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
    char ch1[20],ch2[20],ch3[20];
    cin>>ch1>>ch2;
    int i=0;
    long a1[3],a2[3],a3[3];
    //切割字符串
    char* s=strtok(ch1,".");
    while(s)
    {
        a1[i++]=atoi(s);
        s = strtok(NULL, ".");
    }
    s=strtok(ch2,".");
    i=0;
    while(s)
    {
        a2[i++]=atoi(s);
        s = strtok(NULL, ".");    
    }

    a3[2]=(a1[2]+a2[2])%29;
    a3[1]=((a1[1]+a2[1])+(a1[2]+a2[2])/29)%17;
    a3[0]=(a1[0]+a2[0])+(a1[1]+a2[1])/17;
    //转化为字符串
    stringstream ss;
    ss<<a3[0]<<"."<<a3[1]<<"."<<a3[2]<<endl;
    ss>>ch3;
    cout<<ch3;
}

发表于 2018-04-05 12:03:17 回复(0)
//模拟即可
#include <bits/stdc++.h>
using namespace std;
int A[5],B[5],C[5];
int main(){
    char ignore;
    scanf("%d%c%d%c%d %d%c%d%c%d",&A[1],&ignore,&A[2],&ignore,&A[3],&B[1],&ignore,&B[2],&ignore,&B[3]);
    C[2]+=(A[3]+B[3])/29,C[3]=(A[3]+B[3])%29;
    C[1]+=(A[2]+B[2]+C[2])/17,C[2]=(A[2]+B[2]+C[2])%17;
    C[1]=A[1]+B[1]+C[1];
    printf("%d.%d.%d\n",C[1],C[2],C[3]);
    return 0;
}

发表于 2018-03-02 22:28:44 回复(0)
#include<iostream>
using namespace std;


int main()
{
    int Galleon, Sickle, Knut, Galleon1, Sickle1, Knut1;
    scanf("%d.%d.%d %d.%d.%d", &Galleon, &Sickle, &Knut, &Galleon1, &Sickle1, &Knut1);
    int Galleon2, Sickle2, Knut2;

    Galleon2 = Galleon + Galleon1;
    Sickle2 = Sickle + Sickle1;
    Knut2 = Knut + Knut1;
    
    Sickle2 += (Knut2/29);
    Knut2 %= 29;
    Galleon2 += (Sickle2/17);
    Sickle2 %= 17;
    cout << Galleon2 << "." << Sickle2 << "." << Knut2;

    system("pause");
    return 0;
}
发表于 2018-02-11 17:55:50 回复(0)
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a[3],b[3],c[3];
    scanf("%d.%d.%d",&a[0],&a[1],&a[2]);
    scanf("%d.%d.%d",&b[0],&b[1],&b[2]);
    c[0]=c[1]=c[2]=0;
      c[2]=(a[2]+b[2])%29;
      c[1]+=(a[2]+b[2])/29+(a[1]+b[1])%17;
    c[0]+=(a[1]+b[1])/17+a[0]+b[0];
    printf("%d.%d.%d",c[0],c[1],c[2]);
    return 0;
}

发表于 2017-10-04 14:03:36 回复(0)
int main()
{
char a[100], b[100];
int a1, b1, c1, a2, b2, c2,a3,b3,c3;
scanf("%d.%d.%d", &a1, &b1, &c1);
scanf("%d.%d.%d", &a2, &b2, &c2);
int ca1, ca2;//表示进位
c3 = (c1 + c2) % 29;
ca1 = (c1 + c2) / 29;
b3 = (b1 + b2 + ca1) % 18;
ca2 = (b1 + b2 + ca1) / 18;
a3 = (a1 + a2 + ca2);
printf("%d.%d.%d\n", a3, b3, c3);
return 0;
}
发表于 2017-06-19 22:37:25 回复(0)
include<stdio.h>
#include<math.h>
int main(){
int a,b,c,d,e,sum=0,m,n,g=0,f;
int v=10953871,q=14;
scanf("%d.%d.%d",&a,&b,&c);
scanf("%d.%d.%d",&d,&e,&f);
     if(c+f>=29)
       m=b+e+1;
else 
m=b+e;
     if(m>=17)
  n=a+d+1;
else
n=a+d;
if(c+f==29&&m>17)
    printf("%d.%d.%d\n",n,m-17,g);
else if(c+f==29&&m==17)
         printf("%d.%d.%d\n",n,g,g);
else if(c+f==29&&m<17)
         printf("%d.%d.%d\n",n,m,g);
if(c+f>29&&m>17)
    printf("%d.%d.%d\n",n,m-17,c+f-29);
else if(c+f>29&&m==17)
         printf("%d.%d.%d\n",n,g,c+f-29);
else if(c+f>29&&m<17)
         printf("%d.%d.%d\n",n,m,c+f-29);
if(c+f<29&&m>17)
    printf("%d.%d.%d\n",n,m-17,c+f);
else if(c+f<29&&m==17)
         printf("%d.%d.%d\n",n,g,c+f);
else if(c+f<29&&m<17)
         printf("%d.%d.%d\n",n,m,c+f);

}
发表于 2016-05-13 09:30:03 回复(0)