123456789101112131415161718192021222324252627#include "iostream"using namespace std;int main() { int length; cout << "请输入数组长度:"; cin >> length; int *arr = new int[length]; cout << "请输入数组元素:" << endl; for (int i = 0; i < length; i++) { cin >> arr[i]; } //冒泡排序 for (int i = 0; i < length; ++i) { for (int j = 0; j < length-i-1; ++j) { if (arr[j]>arr[j+1 ...
字符串最后一个词的长度123456789101112131415161718192021import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input=scanner.nextLine(); int sum=0,a=0; for (int i = input.length()-1; i >=0 ; i--) { if (input.charAt(i) != ' ') { for (int j = i; j >= 0 && input.charAt(j) != ' '; j--) { sum++; ...
判断旋转词1234567891011121314151617181920212223242526272829303132import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入两个字符串:"); String str1 = scanner.nextLine(); String str2 = scanner.nextLine(); System.out.println(judgment(str1, str2) ? "是旋转词" : "不是旋转词"); } public static String switchArr(String str) { if ...
随机生成验证码前两位为大写字母,后两位为小写字母,最后一位为数字
1234567891011121314151617181920212223import java.util.Random;public class Main { public static void main(String[] args) { System.out.println("随机输出5个验证码"); for(int i=1;i<=5;i++) { System.out.println(verificationCode()); } } public static String verificationCode(){ Random random = new Random(); String code=""; for(int i=1;i<=2;i++){ ...
压缩字符串压缩字符串 题目描述 实现一个算法来压缩一个字符串。压缩的要求如下: 1.需要判断压缩能不能节会空间,仅在压缩后字符昌比原字符串长度更短时进行缩。 2.压缩的格式是将连续相同字符替换为字符 +数字形式,列如”AAABCCDDDD”变为”A3BC2D4” 输入描述 输入一行字符串,长度不超过 500 输出描述 输出一行。若输入的字符串可压缩,则输出压缩后的字符否则输出 0。
123456789101112131415161718192021222324252627282930313233#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ int n = 0; char str[500]; char str2[500] = {'\0'}; fgets(str, 500, stdin); for (int i = 0; i < strlen(str); i++) { int times = 1; ...
幸运数小蓝认为如果一个数含有偶数个数位,并且前面一半的数位之和等于后面一半的数位之和,则这个数是他的幸运数字。例如 2314 是一个幸运数字,因为它有 4个数位,并且2+3-1+4。现在请你帮他计算从1至100000000 之间共有多少个不同的幸运数字。
1234567891011121314151617181920212223242526272829303132333435#include <stdio.h>int main(){ int a = 0; for (int i = 10; i < 100000000; i++) { int b = 0; for (int j = i; j > 0; j /= 10) { b++; } if (b % 2 == 0) { int sum1 = 0; int sum2 = 0; int p = i; for (int q = 1; q < b+1; q++,p /= 10) { sum1 += p % 10; ...
将一个三位数转化为英文输出12345678910111213141516171819202122232425262728#include <stdio.h>int main(){ printf("请输入一个三位数:\n"); int num,unit,decade,hundred; scanf("%d", &num); char arr1[][10] = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"}; char arr2[][10] = {"TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOU ...
确定精度下求sinx123456789101112131415#include <stdio.h>#include <math.h>int main(){ double eps,x; scanf("%lf%lf",&x,&eps); double num=x,sum=x; for(int n=1;fabs(num)>=eps;n++) { num*=-1*x*x/((2*n)*(2*n+1)); sum+=num; } printf("sinx=%lf",sum); return 0;}
投票系统123456789101112131415161718192021222324252627282930313233343536373839404142#include <stdio.h>#include <stdlib.h>#include <string.h>struct vote { int id; char name[10]; int number;}vote_people[4] ={ {1, "李明",0 },{2, "刘亮", 0 },{3, "王鱼", 0 },{4, "艾日", 0 } };int main(){ for (int i = 1; i <= 10; i++) { int id; printf("请输入投票编号:"); scanf("%d", &am ...
传信游戏123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include<stdio.h>#include<stdlib.h>#include<stdbool.h>bool loopCheck(int* arr, int n, int p);int result(int* arr, int count);int main(){ int n, time = 0; scanf("%d", &n); int* arr = (int*)malloc(sizeof(int) * n); int arr2[1000] = {0}; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int i = 0; i < n; i++) ...