Arvin Liu @ Sprout
tlk.io/clang
10.5.6.94:8788
xx.x.x.xx:8788/recorder
你又不知道他裡面在幹嘛?
反正結果符合你的預期就好啦~
但是你不知道你用的那個人做了什麼。
函式庫:放很多個函式的倉庫。
#include <iostream>就是一種。
只吃float/double/int
char A[] = "123456789";
std::cout << A << std::endl;
std::cout << A+3 << std::endl;
std::cout << A+6 << std::endl;
Output:
123456789
456789
789
char A[] = "123456789";
std::cout << A << std::endl;
std::cout << A+3 << std::endl;
std::cout << A+6 << std::endl;
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | '\0' |
---|
A
A+3
A+6
要#include <cstring>喔!
char S[100];
cin >> S;
cout << strlen(S);
Input:
abcdef
Output:
6
for(int i=0; i< strlen(S); i++)
// do something
int len = strlen(S);
for(int i=0; i< len ; i++)
// do something
Maybe TLE (它其實是個雙層迴圈)
Maybe AC
char S[100];
cin >> S;
cout << (strcmp(S,"QAQ") == 0);
Input:
abcdef
-------
QAQ
Output:
0
----
1
if("ABCD" == S){
// Do something.
}
不會CE,但是結果不一樣。
詳情請見指標。
要#include <cstring>喔!
char str[80];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
puts (str);
Output:
these strings are concatenated.
char str1[] = "Sample string";
char str2[40];
strcpy (str2,str1);
puts (str2);
Output:
Sample string
0123456789
9012345678
8901234567
7890123456
6789012345
5678901234
4567890123
3456789012
2345678901
1234567890
S+len-1
S+len-2
S+len-3
S+len-4
01234567890
901234567890
8901234567890
78901234567890
678901234567890
5678901234567890
45678901234567890
345678901234567890
2345678901234567890
12345678901234567890
strcat
'\0'
01234567890
901234567890
8901234567890
78901234567890
678901234567890
5678901234567890
45678901234567890
345678901234567890
2345678901234567890
12345678901234567890
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char S[1001],S2[2001];
cin >> S;
int len = strlen(S);
for( int i = len-1 ; i>=0 ; i-- ){
strcpy(S2,S+i);
strcat(S2,S);
S2[len] = 0;
cout << S2 << endl;
}
}
Hint: 外面一層while迴圈,每次輸出都Sleep,最後在換行的地方改成回車符號。
#455 - 縮略詠唱可不是簡單的事情呢!
char Spell_book [100][100][161];
Spell_book [i][j][k]
strcmp( Spell_book [i][k],
Spell_book [j][k] ) 是不是0
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
char S[100][100][161];
int main(){
int N;
cin >> N;
for(int i=0;i<N;i++){
int M;
cin >> M;
for(int j=0;j<M;j++){
cin >> S[i][j];
}
}
for(int i=0;i<N;i++){
int max_match = 0;
for(int j=0;j<N;j++){
if(i == j)
continue;
else{
for(int k=0;k<100;k++){
if(strcmp(S[i][k],S[j][k])!=0){
max_match = max(max_match,k);
break;
}
}
}
}
cout << max_match +1 << endl;
}
return 0;
}