Skip to content

Instantly share code, notes, and snippets.

@wihoho
Created December 1, 2013 08:55
Show Gist options
  • Save wihoho/7730146 to your computer and use it in GitHub Desktop.
Save wihoho/7730146 to your computer and use it in GitHub Desktop.
第3周 字符串 作业题
#include <iostream>
using namespace std;
void getResult(char str[]){
int numbers[26];
for(int j = 0; j < 26; j ++)
numbers[j] = 0;
int i = 0;
while(str[i] != '\0'){
numbers[str[i] - 'a'] ++;
i ++;
}
i = 0;
char maxChar = 0;
int max = numbers[0];
for(int j = 1; j < 26; j ++){
if(max < numbers[j]){
max = numbers[j];
maxChar = j;
}
}
maxChar = maxChar + 'a';
cout <<maxChar<<" "<<max<<endl;
}
int main(){
int cases;
cin >> cases;
for(int i = 0; i < cases - 1; i ++){
char str[1001];
cin >> str;
getResult(str);
}
char str[1001];
cin >> str;
getResult(str);
return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const char END_STR[] = "ENDOFINPUT";
int main()
{
char str[20],chs[300];
while(gets(str),strcmp(str,END_STR) != 0)
{
gets(chs);
int length = strlen(chs);
for(int i = 0; i < length; i++)
{
if(chs[i] >= 'A' && chs[i] <= 'Z') cout<<(char)((chs[i]-'A'-5+26)%26 + 'A');
else cout<<chs[i];
}
cout<<endl;
gets(str);
}
return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void check(string s1, string s2){
if (s1.length() != s2.length()){
cout << "NO" <<endl;
return;
}
int before[26] = {0};
int after[26] = {0};
for(int i= 0; i < s1.length(); i ++){
before[s1.at(i) - 'A'] ++;
after[s2.at(i) - 'A'] ++;
}
sort(before, before + 26);
sort(after, after + 26);
for(int i = 0; i < 26; i ++){
if (before[i] != after[i]){
cout << "NO" <<endl;
return;
}
}
cout << "YES" <<endl;
}
int main(){
string s1, s2;
getline(cin, s1);
getline(cin, s2);
check(s1, s2);
return 0;
}
#include <iostream>
using namespace std;
char input[1000001];
int prefixArray[1000001];
int* prefixFunction(char str[], int size){
prefixArray[0] = -1;
int k = -1;
for(int i = 1; i < size ; i ++){
while(k > -1 && str[k+1] != str[i])
k = prefixArray[k];
if(str[i] == str[k+1])
k ++;
prefixArray[i] = k;
}
}
int main(){
int number;
int index = 0;
while(1){
cin >> number;
if (number == 0) break;
index ++;
cin >> input;
prefixFunction(input, number);
cout <<"Test case #" <<index<<endl;
for(int i = 1; i <number; i ++){
int preriodLenght = i - *(prefixArray+i);
if((i+1) % preriodLenght == 0){
int many = (i+1) / preriodLenght;
if(many >= 2)
cout << i + 1 <<" " <<many<<endl;
}
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment