Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
438126 黄浙峰老师 【C5-7】我是第几个单词 C++ 通过 100 1 MS 260 KB 778 2026-04-26 16:58:17

Tests(1/1):


#include <iostream> #include <string> using namespace std; int main(){ string s, word; int cnt = 0, total = 0, pos = 0; // 读句子,自动按空格分割单词 while (cin >> s) { cnt++; // 单词序号 // 去掉最后的句号 if (s.back() == '.'){ s.pop_back(); total += s.size(); break; // 句子结束 } total += s.size(); // 统计总字符数 } cin >> word; cin.clear(); cin.seekg(0); cnt = 0; while (cin >> s){ cnt++; if (s.back() == '.') s.pop_back(); if (s == word) { pos = cnt; break; } } if (pos) cout << pos; else cout << total; return 0; }


测评信息: