第五周第五天

91

#include <stdio.h>

#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void regulation(char temp[],int len,int rule) {

int m=0,n=0,i;

for(i=0;i<len;i++) {

if(temp[i]=='W') {

m++;

} else if(temp[i]=='L'){

n++;

}

if((m>=rule||n>=rule)&&(m-n>=2||n-m>=2)) {

printf("%d:%d\n",m,n);

m=0;

n=0;

}

}

if(m!=0||n!=0)

printf("%d:%d\n",m,n);

}

int main(int argc, char *argv[]) {

char temp[300];

int i;

while(scanf("%c",&temp[0])!=EOF) {

i=1;

while(1) {

scanf("%c",&temp[i]);

if(temp[i]=='E') {

break;

}

++i;

}

regulation(temp,i+1,11);

printf("\n");

regulation(temp,i+1,21);

printf("\n");

}

return 0;

}

92

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

typedef struct{

int flaga[30];

int flagb[30];

}flags;

int main(/* int argc, char *argv[] */) {

char s1[30],s2[30],len1,len2,i;

flags flag;

int temp;

while(gets(s1) != NULL){

gets(s2);

len1=strlen(s1);

len2=strlen(s2);

//初始化

for(i=0;i<27;i++){

flag.flaga[i]=flag.flagb[i]=0;

}

//将字符数组s1,s2分别转换成对应数字,给a,b数组对应数字下标的数据标记

for(i=0;i<len1;i++){

//temp=s1[i]-'`';

temp = s1[i] - 'a'+1;

flag.flaga[temp]=1;

}

for(i=0;i<len2;i++){

temp=s2[i]-'`';

flag.flagb[temp]=1;

}

printf("in s1 or s2:");

for(i=1;i<27;i++){

if(flag.flaga[i]==1||flag.flagb[i]==1)

printf("%c",i+96);

}

printf("\n");

printf("in s1 and s2:");

for(i=1;i<27;i++){

if(flag.flaga[i]==1&&flag.flagb[i]==1)

printf("%c",i+96);

}

printf("\n");

printf("in s1 but not in s2 ,or in s2 but not in s1:");

for(i=1;i<27;i++){

if((flag.flaga[i]==1&&flag.flagb[i]!=1)||(flag.flaga[i]!=1&&flag.flagb[i]==1))

printf("%c",i+96);

}

printf("\n");

printf("not in s1 and s2:");

for(i=1;i<27;i++){

if(flag.flaga[i]==0&&flag.flagb[i]==0)

printf("%c",i+96);

}

printf("\n\n");

}

return 0;

}

93

#include <stdio.h>

#include <string.h>

// 最小表示法:返回最小循环串的起始下标(0-based)

int minimal_notation(const char *s, int n) {

int i = 0, j = 1, k = 0;

while (i < n && j < n && k < n) {

char a = s[(i + k) % n];

char b = s[(j + k) % n];

if (a == b) {

k++;

} else {

if (a > b) {

i += k + 1;

} else {

j += k + 1;

}

if (i == j) {

j++; // 避免指针重合

}

k = 0;

}

}

return i < j ? i : j;

}

int main() {

int L;

if (scanf("%d", &L) != 1) return 1;

getchar(); // 读取换行符

static char s[200000]; // 开大一倍,避免越界

int len = 0;

char c;

while ((c = getchar()) != EOF) {

if (c == '\n' || c == '\r') continue; // 忽略换行符

if (len < L) {

s[len++] = c;

}

if (len == L) break;

}

s[len] = '\0';

int start = minimal_notation(s, L);

printf("%d\n", start); // 题目要求从1开始计数,所以+1

return 0;

}

计算机科学的目标包括找到更好地教育人们使用现有计算机的方法,以及对几十年内可能不可行的技术和方法进行高度推测性的研究。所有这些具体目标的基础是希望通过改进信息的使用来改善当今和未来的人类状况。

计算机科学是理论、工程和实验的结合。在某些情况下,计算机科学家开发一种理论,然后根据该理论设计计算机硬件和软件的组合,并对其进行实验测试。这种理论驱动方法的一个例子是开发新的软件工程工具,然后在实际使用中进行评估。在其他情况下,实验可能会产生新的理论,例如发现人工神经网络表现出与大脑中神经元相似的行为,从而产生神经生理学的新理论。

似乎计算机的其他可预测性使得实验变得不必要,因为实验结果应该提前知道。但是,当计算机系统及其与自然世界的交互变得足够复杂时,可能会导致不可预见的行为。因此,实验和传统的科学方法是计算机科学的关键部分。

相关推荐
Darkwanderor1 天前
什么数据量适合用什么算法
c++·算法
zc.ovo1 天前
河北师范大学2026校赛题解(A,E,I)
c++·算法
py有趣1 天前
力扣热门100题之环形链表
算法·leetcode·链表
py有趣1 天前
力扣热门100题之回文链表
算法·leetcode·链表
月落归舟1 天前
帮你从算法的角度来认识二叉树---(二)
算法·二叉树
SilentSlot1 天前
【数据结构】Hash
数据结构·算法·哈希算法
样例过了就是过了1 天前
LeetCode热题100 柱状图中最大的矩形
数据结构·c++·算法·leetcode
wsoz1 天前
Leetcode哈希-day1
算法·leetcode·哈希算法
阿Y加油吧1 天前
LeetCode 二叉搜索树双神题通关!有序数组转平衡 BST + 验证 BST,小白递归一把梭
java·算法·leetcode