惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recorded Future
Recorded Future
C
Cyber Attacks, Cyber Crime and Cyber Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Google Online Security Blog
Google Online Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
WordPress大学
WordPress大学
博客园 - 聂微东
L
LINUX DO - 最新话题
月光博客
月光博客
小众软件
小众软件
T
Troy Hunt's Blog
A
Arctic Wolf
量子位
I
Intezer
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
有赞技术团队
有赞技术团队
N
News and Events Feed by Topic
美团技术团队
The Cloudflare Blog
P
Privacy International News Feed
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
N
News | PayPal Newsroom
Apple Machine Learning Research
Apple Machine Learning Research
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
V
Vulnerabilities – Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
Hacker News: Ask HN
Hacker News: Ask HN
雷峰网
雷峰网

博客园 - wasd

pear安装步骤 linux定时任务的设置 C语言字符串拆分,打开关闭文件 - wasd - 博客园 js-tips 用optgroup 禁用select中的option方法 - wasd - 博客园 DB2常用语句记录 addslashes、get_magic_quotes_gpc函数、stripslashes函数(转来记录一下) - wasd - 博客园 Linux 强制卸载软件 - wasd - 博客园 Setup locally visual host - wasd B:X星球的身份证系统 B:有道搜索框 B:有道饭团 C:Sibonacci - wasd - 博客园 CakePHP支持DB2 PHP 的变量 - wasd - 博客园 DB2 SQLSTATE 消息异常 JDBC中Preparedstatement使用小结 及JDBC插入数据后获得Last insert ID 并行计算简介 PB3编译adobe的例子photoviewer时错误处理
A:另类的异或
wasd · 2010-05-30 · via 博客园 - wasd
描述
对于普通的异或,其实是二进制的无进位的加法
这里我们定义一种另类的异或A op B, op是一个仅由^组成的字符串,如果op中包含n个^,那么A op B表示A和B之间进行n+1进制的无进位的加法。
下图展示了3 ^ 5 和 4 ^^ 5的计算过程
输入
第一行有一个正整数T, 表示下面共有T组测试数据。
接下来T行,每行有一组测试数据,是由空格隔开的三个部分组成:
A B C
A和C是两个十进制整数,B是一个字符串,由n个^组成
1 <= T <= 100, 0<=A,B<2^30, 1<=n<=1000
输出
每个测试数据输出一行,包含一个数字,即该数据的结果,用十进制表示。
样例输入
2
3 ^ 5
4 ^^ 5
样例输出
6
6

 以下是我的解法,不知道哪里有问题,哎,先写出来记录下吧

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner in = new Scanner(System.in);
 6         int count = in.nextInt();
 7         int[] aa = new int[count];
 8         for(int i=0;i<count;i++)
 9         {
10             int a = in.nextInt();
11             String temp = in.next();
12             int b = in.nextInt();
13             
14             int len = temp.length()+1;
15             if(a<b)
16             {
17                 int c = a;
18                 a = b; 
19                 b = c;
20             }
21             String tep = func(a,b,len);
22             aa[i]=output(tep,len);
23         }
24         for(int i=0;i<count;i++)
25         {
26             System.out.println(aa[i]);            
27         }
28     }
29     //转换成n+1进制
30     public static String change(int a,int len,String result)
31     {
32         result = (a%len)+result;
33         if(a/len>0)return change(a/len,len,result);
34         return result;
35     }
36    //进行计算
37     public static String func(int a,int b,int len)
38     {
39         String ta = change(a,len,"");
40         String tb = change(b,len,"");
41         int max = ta.length();
42         int min = tb.length();
43           for(int k=min; k<max;k++)
44           {
45               tb = "0"+tb;
46           }
47         String result ="";
48 
49         for(int i=0;i<max;i++)
50         {
51             int asd = (Integer.parseInt(tb.substring(i,i+1))+ Integer.parseInt(ta.substring(i,i+1)))%len;
52             result += String.valueOf(asd);          
53         }
54         return result;
55     }
56     //转换回10进制
57     public static int output(String result,int len)
58     {
59         int ok = 0;
60         int bei = 1;
61         for(int i = result.length()-1;i>=0;i--)
62         {
63             int cu = Integer.parseInt(result.substring(i,i+1));
64             ok += cu*bei;
65             bei*=len;
66         }
67         return ok;
68     }
69 }