摘要: Rotating SentencesIn ``Rotating Sentences,'' you are asked to rotate a series of input sentences 90 degrees clockwise. So instead of displaying the input sentences from left to right and top to bottom, your program will display them from top to bottom and right to left.Input and OutputAs inp 阅读全文
posted @ 2013-07-19 01:00 purgiant 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 输入非负整数m和n,输出组合数,其中。在这里,我们使用公式来简化计算。 1 #include 2 3 using namespace std; 4 int combine(int n,int m){ //计算n中取m个组合数 5 int result=1; 6 if(m+m<n) //C_n^m=C_n^{n-m} 7 m=n-m; 8 for(int i=1,j=n-m+1;i<=m;i++,j++) 9 result=result*j/i;10 return result;11 }12 int main(){13 ... 阅读全文
posted @ 2013-07-13 14:56 purgiant 阅读(358) 评论(0) 推荐(0) 编辑
摘要: 编写程序,读入一行恰好包含一个加号、减号或乘号的表达式,输出它的值。这个运算符保证是二元运算符,且两个运算数均为不超过100的非负整数。运算数和运算符可以紧挨着,也可以用一个或多个空格、TAB隔开。行首末尾均可以有空格。提示:选择合适的输入方法可以将问题简化。 样例输入:1+1 样例输出:2 样例输入:2- 5 样例输出:-3 样例输入:0 *1982 样例输出:0 1 #include 2 using namespace std; 3 4 int main(){ 5 int a,b,result; 6 char c; 7 while(cin>>a... 阅读全文
posted @ 2013-07-12 14:37 purgiant 阅读(324) 评论(0) 推荐(0) 编辑
摘要: 输入若干个整数(可以是正数、负数或者零),输出它们的乘积的末3位。这些整数中会混入一些由大写字母组成的字符串,你的程序应当忽略它们。提示:试试看,在执行scanf("%d")时输入一个字符串会怎样?C版本: 1 #include 2 using namespace std; 3 4 const int magic=100; 5 char str[magic]; 6 int main(){ 7 int n,product=1,num; 8 while(1){ 9 num=scanf("%d",&n); //scanf("%d") 阅读全文
posted @ 2013-07-12 11:09 purgiant 阅读(332) 评论(0) 推荐(0) 编辑
摘要: 用1,2,3,…,9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要求abc:def:ghi=1:2:3。输出所有解。提示:不必太动脑筋。 1 #include 2 #include 3 using namespace std; 4 5 int main(){ 6 int array[10]; 7 for(int abc=100;abc<333;abc++){ 8 int def=2*abc,ghi=3*abc; 9 memset(array,0,sizeof(array));10 array[abc/100]... 阅读全文
posted @ 2013-07-12 10:28 purgiant 阅读(257) 评论(0) 推荐(0) 编辑