2020.08.30
I'm so vegetable
在看题解的时候疑惑cin >> s + 1
是什么
// cin为类istream的对象名,cin >> s + 1此句等效bai于cin.operator(s + 1).看下面的例du子:
#include <iostream>
using namespace std;
int main(){
char s[6];
cin >> s + 1;
s[0] = 'c';
cout << s << endl;
}
// 就相当于将输入的字符串放到了字符串的第二个元素之后的空间。
ac代码
//char
#include<iostream>
#include<cstring>
using namespace std;
int n[130];//用来存储字母的个数
char s[1000005];
int main(){
cin >> s + 1;
int r = 0, l = 1, num = 0;
int len = strlen(s + 1);
int res = 1000000;
while(l <= len){
while(r < len && num < 26){
n[s[++r]]++;
if(n[s[r]] == 1) num++;
}
if(num == 26) res = min(res, r - l + 1);
if(n[s[l]] == 1) num--;
n[s[l++]]--;
}
cout << res;
return 0;
}
//string
#include<iostream>
#include<string>
using namespace std;
int n[130];//用来存储字母的个数
string s;
int main(){
cin >> s;
int r = -1, l = 0, num = 0;
int len = s.length();
int res = 1000000;
while(l < len){
while(r < len - 1 && num < 26){
n[s[++r]]++;
if(n[s[r]] == 1) num++;
}
if(num == 26) res = min(res, r - l + 1);
if(n[s[l]] == 1) num--;
n[s[l++]]--;
}
cout << res;
return 0;
}
疑惑
#include<iostream>
#include<cstring>
using namespace std;
char s[1000005];
int main(){
cin >> s + 1;
int len = strlen(s + 1);
int len2 = strlen(s) + 1;
int len3 = strlen(s);
cout << len << endl;
cout << len2 << endl;
cout << len3 << endl;
return 0;
}
// 输入
// ykjygvedtysvyymzfizzwkjamefxjnrnphqwnfhrnbhwjhqcgqnplodeestu
// 输出
// 60
// 1
// 0
上面部分的解释是,s首先是全局数组,默认初始化为0,c的字符串以0为终止符,在s+1开始读取,strlen会找到第一个位置,然后返回从起点到-1的个数
这段时间窝在自习室,每天很缓慢的打卡学习,有时候还学不进去,这个时候会想别人都是怎么做到的能够很专注地去做一件事情呢。思虑到最后,慢慢来吧,毕竟着急也没用。这个时候是在还之前偷懒欠下的债。
要是能一直坚持地学下去也挺好的OwO