Skip to content

Quiz0 #1

@lyss0306

Description

@lyss0306

`#include
#include

int suffixCount(std::string S, int L) {
// Your code here
std::string suff = "";
int count;

//identify full suffix
for(int i = S.length()-L; i<S.length(); i++){
	suff.push_back(S.at(L));
}

//find suffix in string
if(suff.length() == 1){
	for(int i=0; i < S.length(); i++){
		if(suff.at(0) == S.at(i)){
			count += 1;
		}
	}
}
else if(suff.length()==0){
	return 0;
}
else{
	int subCount = 0;
	for(int i=0; i<S.length(); i++){
		for(int j=0; j<suff.length(); j++){
			if(suff.at(j) == S.at(i)){
				subCount += 1;
			}
			if(subCount == suff.length()){
				count += 1;
			}
			
		}
	}
}



//std::cout << suff << std::endl;				//testing
return count;

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions