| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4110 人关注过本帖
标题:[讨论]第三期题目,大家做做.
取消只看楼主 加入收藏
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
结帖率:50%
收藏
 问题点数:0 回复次数:7 
[讨论]第三期题目,大家做做.

Round and Round We Go

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 1293 Accepted Submit: 630

--------------------------------------------------------------------------------

Problem

A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a “cycle” of the digits of the original number. That is, if you consider the number after the last digit to “wrap around” back to the first digit, the sequence of digits in both numbers will be the same, though they may start at different positions.

For example, the number 142857 is cyclic, as illustrated by the following table:

142857 * 1 = 142857
142857 * 2 = 285714
142857 * 3 = 428571
142857 * 4 = 571428
142857 * 5 = 714285
142857 * 6 = 857142

Write a program which will determine whether or not numbers are cyclic. The input file is a list of integers from 2 to 60 digits in length. (Note that preceding zeros should not be removed, they are considered part of the number and count in determining n. Thus, “01” is a two-digit number, distinct from “1” which is a one-digit number.)


Output

For each input integer, write a line in the output indicating whether or not it is cyclic.


Example

Input

142857
142856
142858
01
0588235294117647

Output

142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic


/*看给出的例子应该可以看得懂.*/

搜索更多相关主题的帖子: limit Round Submit integer 
2006-11-26 20:19
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

Martian Addition

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 3228 Accepted Submit: 1090

--------------------------------------------------------------------------------
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are very fond of mathematics. Every year, they would hold an Arithmetic Contest on Mars (ACM). The task of the contest is to calculate the sum of two 100-digit numbers, and the winner is the one who uses least time. This year they also invite people on Earth to join the contest.
As the only delegate of Earth, you're sent to Mars to demonstrate the power of mankind. Fortunately you have taken your laptop computer with you which can help you do the job quickly. Now the remaining problem is only to write a short program to calculate the sum of 2 given numbers. However, before you begin to program, you remember that the Martians use a 20-based number system as they usually have 20 fingers.

Input:
You're given several pairs of Martian numbers, each number on a line.
Martian number consists of digits from 0 to 9, and lower case letters from a to j (lower case letters starting from a to present 10, 11, ..., 19).
The length of the given number is never greater than 100.

Output:
For each pair of numbers, write the sum of the 2 numbers in a single line.

Sample Input:

1234567890
abcdefghij
99999jjjjj
9999900001


Sample Output:

bdfi02467j
iiiij00000

/*20进制大数的加法,只要细心,就可以做的出来.*/


倚天照海花无数,流水高山心自知。
2006-11-26 20:21
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
以下是引用我不是郭靖在2006-11-27 21:16:07的发言:

是啊,还有33 * 3也不是
但从前边分析2-60长度的只有8个序列,所以只要和这8个序列比较就行了.

#include <stdio.h>
#include <string.h>

char *s[] =
{
"142857",
"0588235294117647",
"052631578947368421",
"0434782608695652173913",
"0344827586206896551724137931",
"0212765957446808510638297872340425531914893617",
"0169491525423728813559322033898305084745762711864406779661",
"016393442622950819672131147540983606557377049180327868852459"
};

int main()
{
char str[100];

while (EOF != scanf("%s", str))
{
int i, n;

n = sizeof s / sizeof s[0];
for (i = 0; i < n; i++)
if (strcmp(s[i], str) == 0)
{
printf("%s is cyclic\n", str);
break;
}
if (i == n)
printf("%s is not cyclic\n", str);
}

return 0;
}

在竞赛时,这个是最有效的方法.但是,为了做好题目,应该要写出个程序来.而不是这个样子的.


倚天照海花无数,流水高山心自知。
2006-11-28 10:56
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

希望大家继续.


倚天照海花无数,流水高山心自知。
2006-11-29 20:46
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
以下是引用huoshi91在2006-11-28 17:15:13的发言:
static void Main(string[] args)
{
Console.WriteLine("请输入第一个10位数");
string s1=Console.ReadLine();
Console.WriteLine("请输入第二个10位数");
string s2=Console.ReadLine ();
int[] s3=new int [10];
int i=0;
while( i<10)
{
int s=0;
s =((int)GetNumber(Convert.ToChar(s1[i]))-48)+(int)GetNumber(Convert.ToChar(s2[i]));
if(s==0)
{
s3[i]=0;
}
else
{
s=s%20;
s3[i]=s;
}

Console.Write ("{0}",s3[i].ToString ());
i++;
}

}
private static int GetNumber(char s)
{
switch(s)
{
case 'a':
return 10;
case 'b':
return 11;
case 'c':
return 12;
case 'd':
return 13;
case 'e':
return 14;
case 'f':
return 15;
case 'g':
return 16;
case 'h':
return 17;
case 'i':
return 18;

case'j':
return 19;
default:
return
s;

}
}
}

这个第二题是我C#写的,C也一样,请指教

不好意思,某些地方看不懂,所以也不好说.调试一下,如果和给出的测试数据相吻合的话,应该可以通过.


倚天照海花无数,流水高山心自知。
2006-11-29 21:16
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
以下是引用财鸟在2006-12-1 22:38:05的发言:

请你尊重点.要么就做,要么就别废话.


倚天照海花无数,流水高山心自知。
2006-12-01 23:38
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
今天又是星期六.给出参考代码.希望大家继续支持,谢谢.
Round and Round We Go.cpp

#include<stdio.h>
#include<string.h>
#define N 100
typedef struct{
char data[N];
int set[10];
int len;
}link;
int is_in(link round,int n)
{
link a;
int i=0,t=0,d;
while(i<round.len)
{
d=round.data[round.len-1-i]-'0';
d=d*n;
a.data[i]=(d+t)%10+'0';
t=(d+t)/10;
i++;
}
while(t>0)
{
d=t%10;
a.data[i++]=t+'0';
t=t/10;
}
a.len=round.len;
i=0;
while(i<10)
a.set[i++]=0;
i=0;
while(i<a.len)
{
d=a.data[i]-'0';
a.set[d]++;
i++;
}
for(i=0;i<10;i++)
if(a.set[i]!=round.set[i])
return(0);
return(1);
}

int main()
{
#ifndef ONLINE_JUDGE
freopen ("Round and Round We Go.txt","r",stdin);
#endif
link round;
int i,d;
while(EOF!=(scanf("%s",round.data)))
{
i=0;
round.len=strlen(round.data);
while(i<10)
round.set[i++]=0;
i=0;
while(i<round.len)
{
d=round.data[i]-'0';
round.set[d]++;
i++;
}
for(i=1;i<=round.len;i++)
if(is_in(round,i)==0)
{
printf("%s is not cyclic\n",round.data);
break;
}
if(i>round.len)
printf("%s is cyclic\n",round.data);
}
return(0);
}

倚天照海花无数,流水高山心自知。
2006-12-02 17:41
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

Martian Addition.cpp



#include<stdio.h>
#include<string.h>
#define N 150
typedef struct node{
int data[N];
int len;
}link;

void char_int(link &a,char str[],int length)
{
int i;
a.len=length;
for(i=length-1;i>=0;i--)
{
if(str[i]>='a'&&str[i]<='j')
a.data[a.len-i-1]=str[i]-'a'+10;
else
a.data[a.len-i-1]=str[i]-'0';
}
//for(i=0;i<a.len;i++)
//printf("%3d ",a.data[i]);
//printf("\n");
}

void display(link &a)
{
int i;
for(i=a.len-1;i>=0;i--)
{
if(a.data[i]>=10&&a.data[i]<20)
printf("%c",a.data[i]-10+'a');
else
printf("%c",a.data[i]+'0');
}
printf("\n");
}
void Add20(link &a,link &b)
{
int carry,i,len,temp;
len = a.len > b.len ? a.len : b.len;
carry = 0;
for (i =0;i<len;i++)
{
temp = a.data[i] + b.data[i] + carry;
carry = temp/20;
a.data[i] =temp%20;
}
if (carry != 0)
{
a.len = len + 1;
a.data[len] = carry;
}
else
{
a.len = len;
}
display(a);
}


int main()
{
#ifndef ONLINE_JUDGE
freopen("Martian Addition.txt","r",stdin);
#endif
link a,b;
int len1,len2;
int i;
char str1[N],str2[N];
while(EOF!=(scanf("%s%s",str1,str2)))
{
memset (a.data,0,sizeof (int) * N);
memset (b.data,0,sizeof (int) * N);
len1=strlen(str1);
char_int(a,str1,len1);
//display(a);
len2=strlen(str2);
char_int(b,str2,len2);
//display(b);
Add20(a,b);
//for(i=0;i<a.len;i++)
//printf("%3d ",a.data[i]);
//printf("\n");
//display(a);
}
return(0);
}


倚天照海花无数,流水高山心自知。
2006-12-02 17:43
快速回复:[讨论]第三期题目,大家做做.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012239 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved