PAT:1058. A+B in Hogwarts (20) AC

#include<stdio.h>
#include<stdlib.h>
int main()
{
  int a1,b1,c1,a2,b2,c2;              //【思维】168以内的数字可以用两位13进制数表示,大大简化代码
  scanf("%d.%d.%d",&a1,&b1,&c1);
  scanf("%d.%d.%d",&a2,&b2,&c2);
  int ra,rb,rc,tmp;                //ra,rb,rc存放结果的第一、二、三位置数字,tmp存当前的进位
  ra=rb=rc=tmp=0;
  rc=(c1+c2)%29;                  //【skill】通过不断的取余,取进位,加到下一位取余再进位……无需判断,指导处理到头
  tmp=(c1+c2)/29;
  rb=(b1+b2+tmp)%17;
  tmp=(b1+b2+tmp)/17;
  ra=a1+a2+tmp;
  printf("%d.%d.%d",ra,rb,rc);

  //system("pause");
  return 0;
}
时间: 2024-12-16 00:36:06

PAT:1058. A+B in Hogwarts (20) AC的相关文章

PAT 甲级 1058 A+B in Hogwarts (20 分) (简单题)

1058 A+B in Hogwarts (20 分)   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 enou

PAT:1002. 写出这个数 (20) AC

#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char str[111]; scanf("%s",str); int len=strlen(str); int sum=0; for(int i=0 ; i<len ; ++i) sum+=str[i]-'0'; char A[10][5]={"ling","yi",

PAT:1003. 我要通过!(20) AC

#include<stdio.h> #include<string.h> int main() { int n; scanf("%d",&n); while(n--) { char str[110]; scanf("%s",str); int len=strlen(str); int numP=0,numT=0,other=0; //记录P,T,非P,A,T的字符个数 int PI=-1,TI=-1; //记录P T的位置 for(i

PAT:1023. Have Fun with Numbers (20) AC

#include<stdio.h> #include<string.h> char str[30]; //输入的数字 int tmp[30]; //*2后逆序的数字 int cntstr[10]; //输入数字0-9的个数 int tmpI=0,jin=0; //*2的时候的int数组下标和进位数 void Double(char* str,int len1) { memset(tmp,0,sizeof(tmp)); //将str*2并按个位在左,高位在右方式存储 for(int

1058 A+B in Hogwarts (20分)

1058 A+B in Hogwarts (20分) 题目: 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 eno

PAT:1055. The World&#39;s Richest (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Person { char name[10]; int age,money; }P[100010]; bool cmp(Person a,Person b) { if(a.money!=b.money) return a.money>b.money; else if(a.age!=b.age) r

PAT (Advanced Level) 1058. A+B in Hogwarts (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; int a1,b1,c1; int a2,b2,c2; int ans1,ans2,ans3; int main() { scanf("%d.%d.%d",&

1058 A+B in Hogwarts (20分)(水)

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

1058 A+B in Hogwarts (20)

1 #include <stdio.h> 2 int main() 3 { 4 int ans1[3]; 5 int ans2[3]; 6 while(scanf("%d.%d.%d %d.%d.%d",&ans1[0],&ans1[1],&ans1[2],&ans2[0],&ans2[1],&ans2[2])!=EOF) 7 { 8 ans1[0]+=ans2[0]; 9 ans1[1]+=ans2[1]; 10 ans1[