题解分享
题解分享简介
作文标题改 - 题解
include
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
```
int cnt=0;
string t;
getline(cin,t);
int n= stoi(t);
string s;
getline(cin,s);
for(int i=0;i<n;i++){
if(s[i]!=' '){
cnt++;
}
}
cout<<cnt<<'\n';
return 0;
```
}
查看全文
0
0
0
19
作文标题改 - 题解
```
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int c=0;
cin>>s;
while(cin>>s){
c+=s.length();
}
cout<<c;
return 0;
}
```
0
0
2
1
作文标题改 - 题解
```
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int i=0,num=0;
string s;
scanf("%d\n",&n);
getline(cin,s);
while(i<n)
{
if(s[i]!=' ') num++;
i++;
}
cout<<num;
return 0;
}
```
0
0
1
2
作文标题改 - 题解
👍
```C++
#include<bits/stdc++.h>
using namespace std;
int main(){
string n;
string s;
getline(cin,n);
getline(cin,s);
int count=0;
for(int i=0;i<stoi(n);i++){
if(s[i]!=' ') count++;
}
cout<<count;
return 0;
}
```
查看全文
0
0
1
2
作文标题改 - 题解
```
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string n;
string s;
getline(cin,n);
getline(cin,s);
int n1 = stoi(n);
int count = 0;
for(int i = 0; i < n1; i++){
if(s[i] != ' '){
count++;
}
}
cout << count << endl;
return 0;
}
```
查看全文
0
0
1
0
作文标题改 - 题解
include
include
using namespace std;
int main() {
int n;
int i = 0, num = 0;
string s;
scanf("%d\n", &n);
//不好用cin>>n
//cin >> n 会读取整数 5,但不会消耗后面的换行符 \n。
//后续 getline(cin, str) 会立即读取到残留的 \n,导致 str 被赋值为空字符串。
getline(cin, s);
while (i < n)
{
if (s[i] != ' ') num++;
i++;
}
cout << num;
return 0;
}
查看全文
0
0
0
2
作文标题改 - 题解
```
#include <iostream>
#include <vector>
#include <limits>
#include<string>
using namespace std;
int main() {
int a;
string b;
cin >> a;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
getline(cin, b);
b = b.substr(0, a);
int c = 0;
for (char d : b) {
if (d != ' ') {
c++;
}
}
cout << c;
return 0;
}
//输入a,b然后直接历遍非空输出结果
```
查看全文
0
0
0
3
作文标题改 - 题解
```
#include<bits/stdc++.h>
using namespace std;
string n;
string str;
int sum;
int main()
{
getline(cin,n);
//getchar();
getline(cin,str);
int t = stoi(n);
for(int i=0;i<t;i++)
{
if(str[i]!=' ') sum++;
}
cout<<sum<<endl;
return 0;
}
```
查看全文
0
0
0
3
作文标题改 - 题解
``
include
include
include
include
using namespace std;
int main() {
string str,t;
int n=0,m=0;
getline(cin, t);
getline(cin, str);
n = stoi(t);
int size = str.length();
for (int i = 0; i < n; i++) {
if (str[i] != ' ')m++;
}
cout << m;
return 0;
}
查看全文
0
0
0
2
作文标题改 - 题解
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string str, strn;
int cnt = 0;
int main() {
getline(cin, strn);
n = stoi(strn);
getline(cin, str);
for (int i = 0; i < n; i++)
if (str[i] != ' ' && str[i] != '\n')
cnt++;
cout << cnt << endl;
return 0;
}
```
查看全文
0
0
0
1



