字符和
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<cmath>
using namespace std;
#define MaxSize 1000
string s;
map<string ,int > dict;
int len;
bool judge(string S,string T)
{
int i=0,j=0;
while( i<S.length() && j<T.length())
{
if(S[i]== T[i])
{
++ i; ++ j;
}else{
i=i-j+2; j=0;
}
}
if(j>=T.length()){
return true;
}else
{
return false;
}
}
int main()
{
scanf("%s",&s);
len=int (s.length());
for(int i=0;i<len;i++)
{
for(int j=i;j<len;j++)
{
string temp=s.substr(i,j-i+1);
if(judge(s,temp))
{
if(!dict.count(temp))
{
dict.insert(make_pair(temp,1));
}else
{
dict[temp]++;
}
}
}
}
for(map<string,int>::iterator it = dict.begin(); it!=dict.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
return 0;
}
数列
#include <iostream>
#include <algorithm>
using namespace std;
#define MaxSize 1000005
long long a[MaxSize];
long long cha[MaxSize];
int N;
bool flag=false;
long long min_=9999999999999;
int main()
{
cin>>N;
for(int i=0;i<N;i++)
cin>>a[i];
sort(a,a+N);
for(int i=0;i<N-1;i++)
{
cha[i]=a[i+1]-a[i];
if(cha[i]< min_)
min_=cha[i];
}
for(long long i=min_;min_>=1;min_--)
{
flag=false;
for(int i=0;i<N-1;i++)
{
if(cha[i]%min_!=0)
{
flag=true;
}
}
if(!false)
{
break;
}
}
for(long long i=a[0];i<=a[N-1];i=i+min_)
{
cout<<i<<" ";
}
return 0;
}
时间
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
ll time;
cin>>time;
int HH,MM,SS;
int daytime=24*60*60*1000;
HH= (time % daytime) / (60 * 60 * 1000);
MM= ((time % daytime) % ( 60 * 60 * 1000 )) / (60 * 1000);
SS= (((time % daytime) % ( 60 * 60 * 1000 )) % (60 * 1000)) / 1000;
printf("%02d:%02d:%02d",HH,MM,SS);
}
连线
#include<iostream>
#include<cstring>
#include<map>
#include<set>
using namespace std;
struct {
double x;
double y;
}point[25*25];
map<double,set<double> > dict;
int main()
{
int cnt,ans;
cnt=0;ans=0;
ans=20+21;
for(int i=0;i<20;i++)
for(int j=0;j<21;j++)
{
point[cnt].x=i;
point[cnt].y=j;
cnt++;
}
for(int i=0;i<cnt;i++)
{
for(int j=0;j<cnt;j++)
{
if(point[i].x==point[j].x ||point[i].y == point[j].y)
{
continue;
}
double k=(point[j].y-point[i].y)/(point[j].x-point[i].x);
double b=(point[i].y*point[j].x-point[j].y*point[i].x)/(point[j].x-point[i].x);
dict[k].insert(b);
}
}
for(map<double,set<double> >::iterator it=dict.begin();it!=dict.end();it++)
{
set<double> t=it->second;
ans+=t.size();
}
cout<<ans<<endl;
}
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
char map[108][108];
int vis[108][108];
int dir[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
int n;
int ans=0;
bool in(int x,int y){
return x>=0 && x<n && y>=0 && y<n;
}
void dfs(int x,int y,int & num,int & cnt)
{
vis[x][y]=1;
++num;
if(x-1>=0 && map[x-1][y]=='.') cnt++;
else if(y-1 >=0 && map[x][y-1]=='.') cnt++;
else if(x+1 <= n-1 && map[x+1][y]=='.') cnt++;
else if(y+1 <= n-1 && map[x][y+1]=='.') cnt++;
for(int i=0;i<4;i++)
{
int tx=x+dir[i][0];
int ty=x+dir[i][1];
if(in(tx,ty) && map[tx][ty]!='.' && !vis[tx][ty])
{
dfs(tx,ty,num,cnt);
}
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
scanf("%s",map[i]);
}
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(!vis[i][j] && map[i][j] == '#'){
int num=0;
int cnt=0;
dfs(i,j,num,cnt);
if(num==cnt)
{
ans++;
}
}
}
}
cout<<ans<<endl;
}