#include <iostream> #include <string> using namespace std; bool IsValid(string s){ for(int i = 0; i < s.length(); i++) if(s[i] == 'N') return false; return true; } int main(int argc, char *argv[]) { int n, count = 0; string s; cin>>n>>s; int groupLen = n/10; int index = 0; while(index < s.length()){ if(IsValid(s.substr(index,groupLen))) count++; index += groupLen; } cout<<count; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> #include <string> using namespace std; bool IsValid(string s){ for(int i = 0; i < s.length(); i++) if(s[i] == 'N') return false; return true; } int main(int argc, char *argv[]) { int n, count = 0; string s; cin>>n>>s; int groupLen = n/10; int index = 0; while(index < s.length()){ if(IsValid(s.substr(index,groupLen))) count++; index += groupLen; } cout<<count; } |