#include <iostream>#include <cmath>using namespace std; int main(){ int num = -1; unsigned int s = num; //当前位级表示即为最大无符号数 cout << (int)log2(s)+1 << endl; //第一种 int intSize = 0; while(s != 0) { s = s >> 1; intSize
[字符串与数组] Q:Write a method to decide if two strings are anagrams or not 题目:写一个算法来判断两个字符串是否为换位字符串.(换位字符串是指组成字符串的字符相同,但位置不同) 解答: 方法一:假设为ascii2码字符串,那么可以分配两个256大小的int数组,每个数组用于统计一个字符串各个字符出现的次数,最后,比较这两个int数组,看是否每个元素都相同.时间复杂度为O(n). int anagrams1(char* str1,c
题目:首先需要实现一个函数:两个字符串大小比较(不得使用c#/java系统函数)的自定义函数:之后对一个字符串数据进行按升序排序(在排序过程中使用字符串大小比较时,使用自定义的字符串大小比较函数). 以下是对一个字符串数据进行按升序排序我个人想到的实现方案: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class Program { /
46 [程序 46 字符串连接] 题目:两个字符串连接程序 package cskaoyan; public class cskaoyan46 { public static void main(String[] args) { // TODO Auto-generated method stub java.util.Scanner in = new java.util.Scanner(System.in); System.out.println("输入第一个字符串:"); Strin