Find the Difference(类似 Single Number)
来源:互联网 发布:数据库视频教程哪个好 编辑:程序博客网 时间:2024/06/03 16:23
#include<stdio.h>#include<iostream>#include<string.h>char findTheDifference(char* s, char* t) {int i, j,s1=0,s2=0;for (i = 0; i < strlen(s)+1; i++){s1 += s[i];s2 += t[i];}return(char)(s2 - s1);}int main(){char *s = (char*)malloc(sizeof(char) * 100);char *t = (char*)malloc(sizeof(char) * 100);scanf("%s", s);//scanf("%s", t);随机产生char k;k = findTheDifference(s, t);printf("%c", k);system("pause");return 0;}
方法二:
char findTheDifference(char* s, char* t) { char ss=0;int i, j;for (i = 0; i < strlen(s); i++){ss ^= s[i];}for (i = 0; i < strlen(s) + 1; i++){ss ^= t[i];}return ss;}
single number(只有一个出现奇数次)
nt singleNumber(int a[], int n) { int num = 0; for (int i = 0; i < n; ++i) { num ^= a[i]; } return num; }
0 0
- Find the Difference(类似 Single Number)
- Java编程题目-9:find the single number
- LeetCode(389) Find the Difference
- 【LeetCode】389 Find the Difference(java)
- 389. Find the Difference(C语言)
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- Find the Difference
- 160.Find the Difference
- LeetCode389. Find the Difference
- Find the Difference
- 389. Find the Difference
- Leetcode:Find the Difference
- leetcode_389 Find the Difference
- 389. Find the Difference
- 389. Find the Difference
- 《黄自元间架结构九十二法》 详解
- ServleConfig和ServletContext
- Errors running builder 'Android Package Builder' on project 解决办法
- NDK开发入门
- 计算年龄(递归)
- Find the Difference(类似 Single Number)
- bootstrap 表单验证
- LeetCode- 289. Game of Life - 思路详解-C++
- 【AHK】AutoHotkey快速入门相关1(2017.01.11)
- Android Handler学习总结
- CFBundleName系列参数的含义
- 解决链接错误:error LNK2001: 无法解析的外部符号 __iob
- 安卓成长记(三)
- git 查看远程分支、本地分支、删除本地分支