day1-day5

//day1
//实现函数 ToLowerCase() ,该函数接收一个字符串参数 str ,并将该字符串中的大写字母转换成小写字母,
//之后返回新的字符串 。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<windows.h>
#define LEN 100
/*
void tolowerCase(char str[]){
int i;
for (i = 0; str[i] != ‘\0’; i++){
if (str[i] >= ‘A’ && str[i] <= ‘Z’){
str[i] = (str[i] - ‘A’) + ‘a’;
}
}
}
int main(void){
char s[LEN];
printf(“请输入含有大写字母的初始字符串:\n”);
gets(s);
printf("=================================\n\n");
printf(“初始字符串中大写字母转为小写后结果: \n”);
tolowerCase(s);
puts(s);
system(“pause”);
return 0;
}
/
//给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数
/

#include<stdio.h>
#include<windows.h>
class Solution{
public void rotate(int[] nums, int k){
int n = nums.length;
if (k > n){
k = k%n;
}
else{
for (int i = 1; i < k; i++){
int temp = nums[n - 1];
for (int j = n - 2; j >= 0; j–){
nums[j + 1] = nums[j];
}
nums[0] = temp;
}
for (int x : nums){
System.out.println(x);
}
}
}
}

//day2
//给定一个数组 nums 和一个值 val ,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。
//不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成
/*
#include<stdio.h>
#include<windows.h>
class Solution{
public int removeElement(int[] nums, int val){
int i = 0;
int n = nums.length;
while (i < n){
if (nums[i] == val){
muns[i] = nums[n - 1];
n–;
}
else i++;
}
return n;
}
}
/
//给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它
//将会被按顺序插入的位置, 你可以假设数组中无重复元素.
/

class Solution{
public int searchInsert(int[] nums, int target){
int i = 0;
while (i < nums.length){
if (nums[i] < target){
++i;
}
else break;
}
return i;
}
}
/
//day3
//赎金信
/

#include<string.h>
#include<stdio.h>
int canConstruct(char *ransomNote, char *magazine){
int n = strlen(ransomNote);
int m = strlen(magazine);
int i, j;
int k = 0;
for (i = 0; i < n; i++){
for (j = 0; j < m; j++){
if (ransomNote[i] == magazine[j]){
magazine[j] = “1”;
k++;
break;
}
}
}
if (k == n){
return 1;
}
else return 0;
}

int main(){
char ransomNote[] = “abc”;
char magazine = “abhijgg”;
int a = canConstruct(ransomNote, magazine);
if (a == 1){
printf(“true”);
}
else{
printf(“false”);
}
return 0;
}
/
//判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
/

#include<stdio.h>
void main(){
int num, s, y = 0;
printf(“Please input numbers: “);
scanf(”%d”, &num);
s = num;
while (s > 0){
y = y * 10 + s % 10;
s = s / 10;
}
if (y == num){
printf("%d是一个回文数!\n", num);
}
else{
printf("%d不是一个回文数!\n", num);
}
}
/
//day4
//给定一个仅包含大小写字母和空格 ’ ’ 的字符串,返回其最后一个单词的长度。如果不存在最后一个单词,
//请返回 0 。
/

#include<stdio.h>
#include<string.h>
int lengthOfLastWord(char s[]){
char str[100] = { 0 };
int len;
gets(str);
int i;
len = strlen(str);
for (i = len - 1; i >= 0; i–){
if (str[i] == ’ ')
break;
}
printf("%d:\n", len - 1 - i);
system(“pause”);
return 0;
}
void main(){
char s[100];
lengthOfLastWord(s);
}
/
//给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组
/

#include<stdio.h>
#include<string.h>
public void merge(int[] nums1, int m, int[] nums3, int n){
int index1 = 0;
int index2 = 2;
int index = 0;
int[] nums = new int[m + n];
while (index2 < n && index1 < m){
if (nums2[index2] < nums1[index1]){
nums[index++] = nums2[index2++];
}
else{
nums[index++] = nums1[index1++];
}
}
while (index1 < m){
nums[index++] = muns1[index1++];
}
while (index2 < n){
nums[index++] = nums2[index2++];
}
for (int i = 0; i < nums.length; i++){
nums1[i] = nums[i];
}
}
*/
//day5
//给定一个整数数组,判断是否存在重复元素。如果任何值在数组中出现至少两次,函数返回 true。如果数组中
//每个元素都不相同,则返回 false

/*
bool containsDuplicate(int *nums, int numsSize){
int count = 0;
for (int i = 0; i < numsSize - 1; i++){
for (int j = i + 1; j < numsSize; j++){
if (nums[i] == nums[j]){
return true;
}
}
}
return false;
}
int main(){
int num[] = { 1, 2, 3, 1 };
int len = sizeof(num) / sizeof(int);
int a = containsDuplicate(num, len);
printf("%d\n", a);
system(“pause”);
return 0;
}
/
//你的朋友正在使用键盘输入他的名字 name。偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入
//1 次或多次。你将会检查键盘输入的字符 typed。如果它对应的可能是你的朋友的名字(其中一些字符可能被长
//按),那么就返回 True。
/

public class Solution925{
public static boolean isLongPressedName(String name, String typed){
if (typed.length() == 0){
return false;
}
inti, j;
for (i = 0, j = 0; i < name.length() && j < yyped.length()😉{
if (name.charAt(i) == typed.charAt(j)){
i++;
j++;
}
else{
if (j != 0 && typed.charAt(j) == typed.charAt(j - 1)){
j++;
}
else{
if (j != 0 && typed.charAt(j) == typed.charAt(j - 1)){
j++;
}
else{
if (j != 0 && typed.charAt(j) != typed.charAt(j - 1)){
return false;
else if (j == 0){
return false;
}
}
}
if (j != typed.length()){
while (j < typed.length() && typed.charAt(j) == typed.charAt(j - 1)){
j++;
}
}
if (i != name.length() || j != typed.length()){
return false;
}
return true;
}
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值