http://acm.hdu.edu.cn/showproblem.php?pid=1228
one + two = three four + five six = zero seven + eight nine = zero + zero =
3 90 96
/*strcmp函数,比较两个字符串
设这两个字符串为str1,str2,
若str1==str2,则返回零;
若str1>str2,则返回正数;
若str1
#include
char f[10][6]= {"zero","one","two","three","four","five","six","seven","eight","nine"};
int search(char ch[])//将英文数字转化为阿拉伯数字
{
int i;
for(i=0; i<10; i++)
{
if(strcmp(ch,f[i])==0)
{
break;
}
}
return i;
}
int main (void)
{
char count[10];
int a,b;
while(1)
{
a=0;
while(scanf("%s",count)&&strcmp(count,"+")!=0)
{
a=a*10+search(count);//将a数字整合
}
b=0;
while(scanf("%s",count)&&strcmp(count,"=")!=0)
{
b=b*10+search(count);//将b数字整合
}
if(a==0&&b==0)
{
return 0;//a,b同时为零的时候退出
}
else
{
printf("%d\n",a+b);
}
}
return 0;
}
3 1 100 2 2 3 19
Case #1: 14 Case #2: 1 Case #3: 4
#include
#include
int w[1000001];
int sushu(int n)//素数判定
{
int i;
if(n==1)
{
return 0;
}
else
{
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
}
int he (int n)//各个数字相加和
{
int z=0,s=0,j;
while(n!=0)
{
s+=n%10;
n=n/10;
}
return s;
}
int main(void)
{
int t,a,b,i,d,l;
memset(w,0,sizeof(w));
w[0]=0;
w[1]=0;
w[2]=1;
for(i=3;i<=1000000;i++)//放while外面,否则超时
{
l=he(i);
if(sushu(i)==1&&sushu(l)==1)
{
w[i]=w[i-1]+1;
}
else
{
w[i]=w[i-1];
}
}
scanf("%d",&t);
d=0;
while(t--)
{
d++;
scanf("%d%d",&a,&b);
printf("Case #%d: %d\n",d,w[b]-w[a-1]);
}
return 0;
}
2 3 5 4 8
1 2
//简单数学题
#include
int main(void)
{
int t,a,b,i,j,d;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
d=0;
for(i=0;i<=a;i++)
{
for(j=0;j<=a-i;j++)
{
if(b==i+2*j+(a-i-j)*5)
{
d++;
}
}
}
printf("%d\n",d);
}
return 0;
2 6 30
2013/03/30 2013/03/18 2013/04/23 2013/02/22
//年月日的题目又臭又长 代码应该好懂 就是容易错
#include
int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
const int Y=2013,M=3,D=24;
int distinguish(int y)
{
if(y%400==0||(y%4==0&&y%100!=0))
return 1;
return 0;
}
void before(int k)
{
int y = Y,m = M,d = D;
while(k--)
{
if(distinguish(y))
a[2] = 29;
else
a[2] = 28;
d--;
if(d<=0)
{
m--;
if(m<=0)
{
m = 12;
y--;
}
d = a[m];
}
}
printf("%04d/%02d/%02d\n",y,m,d);
}
void after(int k)
{
int y = Y,m = M,d = D;
while(k--)
{
if(distinguish(y))
a[2] = 29;
else
a[2] = 28;
d++;
if(d>a[m])
{
m++;
if(m>12)
{
m = 1;
y++;
}
d = 1;
}
}
printf("%04d/%02d/%02d ",y,m,d);
}
int main(void)
{
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
after(m);
before(m);
}
return 0;
}
2 1(1a2b1(ab)1c) 3(ab2(4ab))
abbabc abaaaabaaaababaaaabaaaababaaaabaaaab
#include
#include
char input[250005];
char str[250005];
int main()
{
int cas;
scanf("%d",&cas);
while (cas--)
{
scanf("%s", input);
int len;
while (1)
{
int flag = 0;
int c = 0;
int i, j, k;
len = strlen(input);
for (i = 0; i < len; i++)
{
if (input[i] >= 'a' && input[i] <= 'z')
{
str[c++] = input[i];//字符
}
else if (input[i] >= '0' && input[i] <= '9')
{
int cnt = 0;
while (input[i] >= '0' && input[i] <= '9')
{
cnt *= 10;
cnt += input[i] - '0';
i++;
}
if (input[i] != '(')
{
while (cnt--)
{
str[c++] = input[i];
}
}
else
{
int t = 1;
int temp = i + 1;
while (t != 0)
{
if (input[temp] == '(')
{
++t;
}
if (input[temp] == ')')
{
--t;
}
++temp;
}
for (j = 0; j < cnt; ++j)
{
for (k = i + 1; k < temp - 1; ++k)
{
str[c++] = input[k];
if (input[k] == '(' || input[k] == ')' || (input[k] >= '0' && input[k] <= '9'))
{
flag = 1;
}
}
}
i = temp - 1;
}
}
}
str[c] = 0;
strcpy(input, str);
if (flag == 0)
{
break;
}
}
puts(str);
}
return 0;
}
Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time0), height of Xaniar is h1 and height of Abol ish2. Each second, Mike waters Abol and Xaniar.
So, if height of Xaniar is h1 and height of Abol ish2, after one second height of Xaniar will become and height of Abol will become wherex1, y1, x2 andy2 are some integer numbers and denotes the remainder ofa modulo b.
Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania isa1 and height of Abol isa2.
Mike has asked you for your help. Calculate the minimum time or say it will never happen.
The first line of input contains integer m (2 ≤ m ≤ 106).
The second line of input contains integers h1 anda1 (0 ≤ h1, a1 < m).
The third line of input contains integers x1 andy1 (0 ≤ x1, y1 < m).
The fourth line of input contains integers h2 anda2 (0 ≤ h2, a2 < m).
The fifth line of input contains integers x2 andy2 (0 ≤ x2, y2 < m).
It is guaranteed that h1 ≠ a1 andh2 ≠ a2.
Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.
5 4 2 1 1 0 1 2 3
3
1023 1 2 1 0 1 2 1 1
-1
In the first sample, heights sequences are following:
Xaniar:
Abol:
//题意:给一个青蛙和一朵花浇水,它们会按每分钟(h*x+y)mod m的速度长高,问它们分别长到a1和a2,最少需要多长时间。
//思路:注意是同时给它们两个浇水啊!!并且是同时长到a1和a2
#include
int main()
{
__int64 h1,a1,x1,y1,h2,a2,x2,y2,m;
__int64 b1,c1,b2,c2;
b1 = c1 = b2 = c2 = -1;
int i;
while(scanf("%I64d",&m)!=EOF)
{
scanf("%I64d %I64d",&h1,&a1);
scanf("%I64d %I64d",&x1,&y1);
scanf("%I64d %I64d",&h2,&a2);
scanf("%I64d %I64d",&x2,&y2);
for(i=1; i<=2*m; i++)//循环节最大到m,估计的时候大点吧 2m
{
h1=(h1*x1+y1)%m;
if(h1==a1)
{
if(b1==-1)
{
b1=i;//最开始的达到a1的时间
}
else if(c1==-1)
{
c1=i-b1;//循环长度
}
}
h2=(h2*x2+y2)%m;
if(h2==a2)
{
if(b2==-1)
{
b2=i;
}
else if(c2==-1)
{
c2=i-b2;
}
}
}
if(b1==-1||b2==-1)
{
printf("-1\n");
}
else if(b1==b2)
{
printf("%I64d",b1);
}
else
{
for(i=1; i<=2*m; i++)
{ if(b1
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 20083 | Accepted: 7721 |
Description
Input
Output
Sample Input
3 3 1 2 3 1 3 1 3 2 1 10 2 1 2 3 4 5 6 7 8 9 10
Sample Output
3 1 2 1 2 3 1 2 3 4 5 6 7 9 8 10
#include
#include
#include
using namespace std;
int a[1025];
void next(int N)
{
int i,j,index=0;
bool flag = false;
for( i=N-2; i>=0; --i )
{
if( a[i]2所以将3与2交换,后面的按小到大排序
//因为这么做的前提是2后面是递减的,所以我们只要从最后找到一个最先位于index和tem之间的值即可,如此循环
for( i=N-1; i>=index+2; --i )
{
if( a[i]a[index])
{
temp = i;
break;
}
}
int change = a[index];
a[index] = a[temp];
a[temp] = change;
sort(a+index+1,a+N);
}
int main()
{
int T;
int N,K;
int i;
scanf("%d",&T);
while( T-- )
{
scanf("%d%d",&N,&K);
for( i=0; i
下面是自己做法 比较简洁
#include
#include
#include
using namespace std;
#define maxn 1028
int f[maxn];
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &f[i]);
while (k--)
next_permutation(f, f + n);
printf("%d", f[0]);
for (int i = 1; i < n; i++)
printf(" %d", f[i]);
printf("\n");
}
return 0;
}
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number w (1≤w≤100) the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
8
YES
//题意:把一个分为两个偶数之和。假设能够分。输出YES 否则输出NO
//值得注意的这道题的背景是两个人分西瓜。所以每一个人至少分到一磅,so 0的情况就要排除掉,尽管0也是偶数
#include
int main() {
int num;
scanf("%d", &num);
printf("%s\n", num % 2 == 0 && num != 2 ? "YES": "NO");
return 0;
}
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.
At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in thet-th block. It is known that Alice never moves outside of the road.
You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.
9 ..RRLL...
3 4
11 .RRRLLLLL..
7 5
#include
#include
char str[1005];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
scanf("%s",str);
int i;
int len=strlen(str);
int flag=0,flag1=0;
int start,end;
for( i=0; i