Sky数
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24477 Accepted Submission(s): 13910
2992 1234 0
2992 is a Sky Number. 1234 is not a Sky Number.
#include<stdio.h>
int change(int n,int x){
int sum=0;
while(n){
sum+=n%x;
n/=x;
}
return sum;
}
int main(){
int n;
while(scanf("%d",&n)&&n){
int s1= change(n,10);
int s2= change(n,16);
int s3= change(n,12);
if(s1==s2&&s1==s3)
printf("%d is a Sky Number.\n",n);
else
printf("%d is not a Sky Number.\n",n);
}
}
Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 47009 Accepted Submission(s): 20879
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
2 ABC ABBCCC
ABC A2B3C
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
char str[1000];
int main(){
int T;
cin>>T;
while(T--){
cin>>str;
int len=strlen(str);
int t=1;
for(int i=0;i<len;i++){
while(str[i]==str[i+1]){
i+=1;
t++;
}
if(t!=1)
{
printf("%d%c",t,str[i]);
t=1;
}
else{
printf("%c",str[i]);
}
}
printf("\n");
}
}
分拆素数和
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 40028 Accepted Submission(s): 17534
30 26 0
3 2
#include <stdio.h>
#include <math.h>
int IsPrime(int n)
{
int i;
for (i=2; i<=sqrt(n); i++)
{
if (n % i == 0)
return 0;
}
return 1;
}
int main()
{
int n, i, cnt;
while (scanf("%d", &n) && n)
{
cnt = 0;
for (i=3; i<n/2; i+=2)
{//因为是不同的两个素数,那必定一个比n/2大,一个比n/2小
if (IsPrime(i) && IsPrime(n-i))
cnt++;
}
printf("%d\n", cnt);
}
return 0;
}
20岁生日
-
描述
- 路过这的20岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达20岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达20岁生日所经过的总天数,让他好来比较一下。
#include <stdio.h>
int main()
{
int year,mon,day,sum1,sum2,sum3,t,i,flag1,flag2;
scanf("%d",&t);
while(t--)
{
flag1=flag2=0;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//保存十二个月的天数,2月先用平年计算
scanf("%d-%d-%d",&year,&mon,&day);
sum1=sum2=sum3=0;
for(i=year+1;i<year+20;i++)
{
if(i%4==0&&i%100!=0||i%400==0)
sum1+=366;
else
sum1+=365;
}//计算出生下一年到20岁那年的天数
if(year%4==0&&year%100!=0||year%400==0)
a[2]=29,flag1=1;//如果出生那年为闰年2月要修改为29天,并且标记flag1=1;
for(i=mon+1;i<13;i++)
sum2=sum2+a[i];
sum2=sum2+a[mon]-day;//计算出生那年到下一年的天数
a[2]=28;
if((year+20)%4==0&&(year+20)%100!=0||(year+20)%400==0)
a[2]=29,flag2=1;//如果二十岁生日那年为闰年flag2=1;
for(i=1;i<mon;i++)
sum3=sum3+a[i];
if(flag1&&!flag2&&mon==2&&day==29)
printf("-1\n");//如果出生那年为闰年且为2月29日, 如果year+20不是闰年,那么这个人没有20岁生日。
else
printf("%d\n",sum1+sum2+sum3+day);
}
return 0;
}
1771: Divisible number
时间限制: 1 Sec 内存限制: 128 MB提交: 1 解决: 1
[ 提交][ 状态][ 讨论版][ Edit] [ TestData]
题目描述
1, 2, 3... ... N this n (0 < n < = 1000000000) in the number of how many Numbers can be divided exactly by positive integer b
输入
Input contains multiple sets of data
Each group of data is a line, each row is given two positive integer n, b.
输出
Input contains multiple sets of data
Each group of data is a line, each row is given two positive integer n, b.
样例输入
2 1
5 3
10 4
样例输出
2
1
2
提示
#include<stdio.h>
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
printf("%d\n",n/m);
}
return 0;
}
Quicksum
-
描述
-
A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.
For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.
A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "
ACM
" and "MID CENTRAL
":ACM: 1*1 + 2*3 + 3*13 = 46 MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 +
9*18 + 10*1 + 11*12 = 650
-
输入
- The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 300 characters. 输出
- For each packet, output its Quicksum on a separate line in the output. 样例输入
-
ACM MID CENTRAL REGIONAL PROGRAMMING CONTEST ACN A C M ABC BBC #
样例输出
-
46 650 4690 49 75 14 15
来源
- POJ
-
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char a[999]; while(gets(a)) { if(a[0]=='#') break; int sum=0,s; for(int i=0;i<strlen(a);i++) { if(a[i]==' ') s=0; else s=(a[i]-'A'+1); sum=(i+1)*s+sum; } printf("%d\n",sum); } }
Fibonacci Again!
时间限制: 1000 ms | 内存限制: 65535 KB难度: 2-
描述
-
求第n个斐波那契数是否是一个素数,n为整数f[n]=f[n-1]+f[n-2] (2<n<30)f[1]=3,f[2]=7
-
输入
-
输入整数m,0<m<30,输入-1表示结束输入
输出
-
如果f[m]是素数 则输出Yes,否则输出No,
每行输出占一行。
样例输入
-
2 3
样例输出
-
Yes No
上传者
- zinber
-
#include<stdio.h> #include<ctype.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> using namespace std; int judge_prime(int n) { int i; for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;//不是素数 return 1;//是素数 } int main() { int n; int a[40]; a[1]=3;a[2]=7; for(int i=3;i<30;i++) { a[i]=a[i-1]+a[i-2]; //printf("%d\n",a[i]); } while(scanf("%d",&n)!=EOF&&n!=-1) { if(judge_prime(a[n])) printf("Yes\n"); else printf("No\n"); } return 0; }
最少拦截系统
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 43290 Accepted Submission(s): 16864
Problem Description某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input8 389 207 155 300 299 170 158 65
Sample Output2/*特殊数据 输入:8 17 16 15 16 13 12 14 12 输出:2 */ #include<stdio.h> int main(int argc,char* argv[]){ int n=0; int a[10000]; while(scanf("%d",&n) != EOF){ int h,k=0; for(int i =0;i<n;i++) scanf("%d",&a[i]); for(int i =0;i<n;i++){ if(a[i] != -1){ h =a[i]; k++; for(int j=i+1;j<n;j++) if(a[j] != -1&&h>=a[j]) { h = a[j]; a[j] =-1; } } } printf("%d\n",k); } return 0; }
-
输入整数m,0<m<30,输入-1表示结束输入
-