量子团队算法训练20190417
#include<stdio.h>
#include<string.h>
char s[1010][110],c[1010];
int main()
{
int n;
while(scanf("%d",&n) && n)
{
getchar();
int i,j,max=0;
for(i=0;i<n;i++)
gets(s[i]);
for(i=0;i<n;i++)
{
int sum=0;
for(j=0;j<n;j++)
{
if(strcmp(s[i],s[j])==0)
//累计单词重复的个数;
sum++;
}
if(sum>max)
//出现比之前单词次数大的单词就替换掉,如此反复,直到找到次数最大的那个
{
max=sum;
strcpy(c,s[i]);
}
}
printf("%s\n",c);
}
return 0;
}
2.
#include<iostream>
using namespace std;
int f(int A, int B,int n)
{
if(n==1 || n==2)
return 1;
else
return (A*f(A,B,n-1)+B*f(A,B,n-2))%7;
}
int main()
{
int a,b,n;
while(cin>>a>>b>>n,a||b||n)
{
cout<<f(a,b,n%49)<<endl;
}
return 1;
}
3.
#include <stdio.h>
#include <string.h>
int main() {
char str[10000];
while (scanf("%s", str) != EOF) {
if (strcmp(str, "0") == 0) {
break;
}
int answer = 10;//技巧
while (answer >= 10) {//是大于等于,不是只有大于
answer = 0;//每次循环归零
for (int i = 0; str[i] != 0; i++) {
answer += str[i] - '0';
}
sprintf(str, "%d", answer);//真的很方便啊!!!!
}
printf("%d\n", answer);
}
return 0;
}
4.
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct Node
{
int dl;
int scr;
} data[1005];
int vis[1005];
int cmp (Node a, Node b)
{
if (a.scr != b.scr)
return a.scr > b.scr;
else return a.dl < b.dl;
}
int main ()
{//freopen("sample.txt", "r", stdin);
int cas;
scanf ("%d", &cas);
while (cas--)
{
int n;
memset (vis, 0, sizeof(vis));
scanf ("%d", &n);
for (int i=0; i<n; ++i)
scanf ("%d", &data[i].dl);
for (int i=0; i<n; ++i)
scanf ("%d", &data[i].scr);
sort (data, data+n, cmp);
int ans = 0;
for (int i=0; i<n; ++i)
{
int j=data[i].dl;
for (; j>=1; --j) // 枚举每一个合法的天数
if(!vis[j])
{
vis[j] = 1;
break;
}
if(j == 0)
ans += data[i].scr;
}
printf ("%d\n", ans);
}
return 0;
}
/*
3
3
3 3 3
10 5 1
3
1 3 1
6 2 3
7
1 4 6 4 2 4 3
3 2 1 7 6 5 4
*/
5.
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;
struct program
{
int start;
int stop;
}a[105];
int n;
bool cmp(program a,program b)
{
if(a.stop==b.stop) //结束时间想同,按开始时间从小到大
{
return a.start<b.start;
}
else return a.stop<b.stop;
}
int main()
{
while(~scanf("%d",&n)&&n)
{
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a[i].start,&a[i].stop);
}
sort(a+1,a+1+n,cmp);
int k=a[1].stop;
int cnt=1; //我假设第一个节目已经被选了
for(int i=2;i<=n;i++)
{
// printf("%d %d\n",a[i].start,a[i].stop);
if(a[i].start>=k) //若开始时间大于上一个节目开始时间
{
cnt++;
k=a[i].stop; //换当前节目的结束时间
}
}
printf("%d\n",cnt);
}
return 0;
}
/*
12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0
*/