课评: 转出学生归档(王子墨/张立坤/黄俊博)+ 周四班级总结 + 新生章梓皓档案 + C++示例代码
This commit is contained in:
38
C++代码/学习/我是第几个单词.cpp
Normal file
38
C++代码/学习/我是第几个单词.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s, a; // s
|
||||
int dc = 0; // 当前是第几个单词
|
||||
int zm = 0; // 当前是第几个字母
|
||||
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
cin >> a;
|
||||
|
||||
string curr = "";
|
||||
for(char c : s){
|
||||
if(c == ' ' || c == '.'){
|
||||
// 中断
|
||||
// 出现一个单词
|
||||
// if(curr.size() == 0){
|
||||
// continue;
|
||||
// }
|
||||
dc++; // 单词数加一
|
||||
cout << curr << " ";
|
||||
if(curr == a){
|
||||
cout << dc;
|
||||
return 0;
|
||||
}
|
||||
curr = "";
|
||||
|
||||
} else {
|
||||
curr += c;
|
||||
zm++; // 字母数加一
|
||||
}
|
||||
}
|
||||
|
||||
cout << zm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user