Axelrod

Axelrod
18天前
#include<iostream>
#include<vector>
using namespace std;
int n,b;
vector<int> ans;

bool f()
{
for(int i=0,j=ans.size()-1;i<j;i++,j--)
if(ans[i]!=ans[j])
return false;
return true;
}
int main()
{
cin>> n>>b;
int m=n;
while(n)
{
int t=n%b;
ans.push_back(t);
n/=b;
}
if(f())
printf("Yes\n");
else
printf("No\n");
if(m==0)
printf("0");
else
for(int i=ans.size()-1;i>=0;i--)
printf("%d ",ans[i]);
return 0;
}



Axelrod
1个月前
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool judge(int a)
{
if(a<2)
return false;
for(int i=2;i<=a/i;i++)
if(a%i==0)
return false;
return true;
}
int main()
{
int t,k;
while(cin >> t,t>=0)
{
cin >> k;
if(!judge(t))
{
printf("No\n");
continue;
}
vector<int> m;
while(t)
{
m.push_back(t%k);
t/=k;
}
int n=0;
for(int i=0;i<m.size();i++)
n=n*k+m[i];
if(judge(n))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}


Axelrod
1个月前
#include<iostream>
#include<vector>
using namespace std;
int n;
char name[24][4]={"jan","feb","mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int main()
{
cin >> n;
getchar();
while(n--)
{
string a;
getline(cin,a);
if(a[0]>='0'&&a[0]<='9')
{
int res=0;
for(int i=0;i<a.size();i++)
res=res*10+a[i]-'0';
if(res<13&&res>0)
cout << name[res-1];
else if(res==0)
cout << "tret" ;
else if(res%13==0)
{
res/=13;
cout << name[res+11];
}
else
{
int t=res/13;
res=res-t*13;
cout << name[t+11] << " " << name[res-1] ;
}
}
else
{
if(a.size()>5)
{
int idx,res=0;
for(int i=12;i<24;i++)
if(a[0]==name[i][0]&&a[1]==name[i][1]&&name[i][2]==a[2])
idx=i;
res+=13*(idx-11);
for(int i=0;i<12;i++)
if(a[4]==name[i][0]&&a[5]==name[i][1]&&name[i][2]==a[6])
idx=i;
res+=idx+1;
cout << res;
}
else
{
int idx,res=0;
if(a[0]=='t'&&a[1]=='r'&&a[2]=='e')
cout << "0";
else
{
for(int i=0;i<24;i++)
if(a[0]==name[i][0]&&a[1]==name[i][1]&&name[i][2]==a[2])
idx=i;
if(idx<12)
res=idx+1;
else
res=13*(idx-11);
cout << res ;
}
}
}
if(n!=0)
cout << endl;
}
return 0;
}



Axelrod
1个月前
#include<iostream>

using namespace std;

int main()
{
printf("#");
int t;
for(int i=0;i<3;i++)
{
cin >> t;
int sum;
sum=t/13;
if(sum<10)
printf("%d",sum);
else
printf("%c",'A'+sum-10);
t-=13*sum;
if(t<10)
printf("%d",t);
else
printf("%c",'A'+t-10);
}
return 0;
}


Axelrod
2个月前
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

{
vector<int> b;
b.assign(a.begin(),a.end());
reverse(b.begin(),b.end());
vector<int> res;
int t=0;
for(int i=0;i<a.size()||t;i++)
{
if(i<a.size())
t+=a[i]+b[i];
res.push_back(t%10);
if(t>=10)
t=1;
else
t=0;
}
return res;
}

bool judge(vector<int> a)
{
for(int i=0,j=a.size()-1;i<j;i++,j--)
if(a[i]!=a[j])
return false;
return true;
}
vector<int> q;
int main()
{
bool flag=false;
string a,b;
int k;
cin >> a >> k;
for(int i=a.size()-1;i>=0;i--)
q.push_back(a[i]-'0');
int i;
for(i=0;i<k;i++)
{
if(judge(q))
{
flag=true;
break;
}
}
for(int i=q.size()-1;i>=0;i--)
printf("%d",q[i]);
printf("\n");
if(flag)
printf("%d",i);
else
printf("%d",k);
return 0;
}


Axelrod
2个月前
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int n[15];
vector<int> m,res;
int main()
{
string a;
cin >> a;
for(int i=a.size()-1;i>=0;i--)
{
n[a[i]-'0']++;
m.push_back(a[i]-'0');
}
int t=0;
for(int i=0;i<m.size()||t;i++)
{
if(i<m.size())
t+=2*m[i];
res.push_back(t%10);
n[t%10]--;
if(t>=10)
t=1;
else
t=0;
}
bool flag=false;
for(int i=0;i<10;i++)
if(n[i]!=0)
{
printf("No\n");
flag=true;
break;
}
if(!flag)
printf("Yes\n");
reverse(res.begin(),res.end());
for(int i=0;i<res.size();i++)
printf("%d",res[i]);
return 0;
}


Axelrod
2个月前
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef pair<int,double> PII;

int a,b;
vector<PII> ans1,ans2;
double ans[2020];
int res;

int main()
{
cin >> a;
int t;
double num;
for(int i=0;i<a;i++)
{
cin >> t >> num;
ans1.push_back({t,num});
}
cin >> b;
for(int i=0;i<b;i++)
{
cin >> t >> num;
ans2.push_back({t,num});
}
for(int i=0;i<ans1.size();i++)
{
for(int j=0;j<ans2.size();j++)
{
int p=ans1[i].first+ans2[j].first;
if(fabs(ans[p])<1e-6) res++;
ans[p]+=(double)ans1[i].second*ans2[j].second;
if(fabs(ans[p])<1e-6)
res--;
}
}
cout << res;
for(int i=2020;i>=0;i--)
{
if(fabs(ans[i])>1e-6)
printf(" %d %.1lf",i,ans[i]);
}
return 0;
}


Axelrod
2个月前
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a,b;
double ans[1010];
int res;
int main()
{
cin >> a;
int t;
double num;
for(int i=0;i<a;i++)
{
cin >> t >> num;
if(ans[t]==0)
res++;
ans[t]+=num;
if(fabs(ans[t])<1e-6)
res--;
}
cin >> b;
for(int i=0;i<b;i++)
{
cin >> t >> num;
if(ans[t]==0)
res++;
ans[t]+=num;
if(fabs(ans[t])<1e-6)
res--;
}
cout << res;
for(int i=1000;i>=0;i--)
{
if(fabs(ans[i])>1e-6)
printf(" %d %.1lf",i,ans[i]);
}
return 0;
}


Axelrod
2个月前
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>

using namespace std;
const int N=31*1440+10;
int n;
int cost[24]; //每个时间段的话费
double sum[N]; //表示从当月一号00:00到每个时刻所花费的钱

struct node
{
int minutes; //从第一天 00:00 开始的分钟数
string state;
string format_time;
};
map<string,vector<node>> records;
bool cmp(node a,node b)
{
return a.minutes <b.minutes;
}
int main()
{
for(int i=0;i<24;i++)
cin >> cost[i];
for(int i=1;i<N;i++)
sum[i] = sum[i-1] + cost[(i-1)%1440/60] /100.0;  //利用前缀和预先处理每分钟的花费
cin >> n;
string name,state;
char formattime[20];
int mon,day,hour,minute;
for(int i=0;i<n;i++)
{
cin >> name;
scanf("%d:%d:%d:%d",&mon,&day,&hour,&minute);
cin >> state;
sprintf(formattime,"%02d:%02d:%02d",day,hour,minute);
int minutes=(day-1)*1440+hour*60+minute;
records[name].push_back({minutes,state,formattime});
}

for(auto &item : records)
{
auto name=item.first;
auto record=item.second;
sort(record.begin(),record.end(),cmp);
double total=0;
for(int i=0;i+1<record.size();i++)
{
auto a=record[i] , b=record[i+1];
if(a.state=="on-line"&&b.state=="off-line")
{
if(!total)  printf("%s %02d\n",name.c_str(),mon);
cout << a.format_time << " " << b.format_time;
double c=sum[b.minutes] -sum[a.minutes];
printf(" %d $%.2lf\n",b.minutes-a.minutes,c); total+=c; } } if(total) printf("Total amount:$%.2lf\n",total);
}
return 0;
}



Axelrod
2个月前
#include<iostream>
#include<unordered_map>
#include<algorithm>
using namespace std;
unordered_map<string,int> list;
string m,ans;
int res=-1;
int main()
{
getline(cin,m);
transform(m.begin(),m.end(),m.begin(),::tolower);
for(int k=0;k<m.size();)
{
int r=k;
while(r<m.size()&&((m[r]>='A'&&m[r]<='Z')||(m[r]>='a'&&m[r]<='z')||(m[r]>='0'&&m[r]<='9')))
r++;
if(r-k==0)
{
k++;
continue;
}
string l=m.substr(k,r-k);
list[l]++;
k=r+1;
}
for(auto it : list)
{
if(it.second>res||(it.second==res&&it.first<ans))
{
res=it.second;
ans=it.first;
}
}
cout << ans << " " << res;
return 0;
}