6.表达式求值c++
1+2*3=7 1*(2+3)=5 1*2*3=6 (1+2)*3=9
一行三个数a,b,c (1 <= a, b, c <= 10)
可以得到的最大值
1 2 3
9
1 using System; 2 using System.Text; 3 using System.Text.RegularExpressions; 4 namespace AAAAA 5 { 6 class AA 7 { 8 public static void Main(string[] args) 9 { 10 string str = Console.ReadLine(); 11 string[] arr = Regex.Split(str, " "); 12 int[] shuZu=new int[3]; 13 int n = 0; 14 int sum = 0; 15 foreach (string str2 in arr) 16 { 17 shuZu[n]=Convert.ToInt32(str2); 18 n++; 19 } 20 int[] result=new int[6]; 21 result[0]=shuZu[0]+shuZu[1]+shuZu[2]; 22 result[1]=shuZu[0]*shuZu[1]*shuZu[2]; 23 result[2]=shuZu[0]*shuZu[1]+shuZu[2]; 24 result[3]=shuZu[0]+shuZu[1]*shuZu[2]; 25 result[4]=(shuZu[0]+shuZu[1])*shuZu[2]; 26 result[5]=shuZu[0]*(shuZu[1]+shuZu[2]); 27 Console.WriteLine(Math.Max(result[0],Math.Max(result[1],Math.Max(result[2],Math.Max(result[3],Math.Max(result[4],result[5])))))); 28 } 29 } 30 }
7.模数求和spa
输入包含两行,第一行为一正整数n,(1<n<=3000)1
第二行为n个整数a
,a2
,...,an
,其中(2<=ai
<=10^5)
输出仅包含一行,输出f(m)的最大值
3 3 4 6
10
就样例而言,当m取11时可取得最大值。
1 using System; 2 using System.Text; 3 using System.Text.RegularExpressions; 4 5 namespace WorkAttendance 6 { 7 class Attendance 8 { 9 public static void Main(string[] args) 10 { 11 int m = System.Convert.ToInt32(Console.ReadLine()); 12 string str = Console.ReadLine(); 13 string[] arr = Regex.Split(str, " "); 14 int n = 0; 15 int sum = 0; 16 foreach (string str2 in arr) 17 { 18 sum += Convert.ToInt32(str2) - 1; 19 n++; 20 } 21 Console.WriteLine(sum); 22 } 23 } 24 }
8.二进制中有多少个一code
把一个32-bit整型转成二进制,其中包含多少个1,好比5的二进制表达是101,其中包含2个1blog
输入为整型(十进制),只需兼容32-bit便可,如五、32
输出为字符串,如“2”、“1”
5
2
5的二进制是101,其中包含2个1
1 using System; 2 using System.Text; 3 namespace AAAAA 4 { 5 class AA 6 { 7 public static void Main(string[] args) 8 { 9 int a = Convert.ToInt32(Console.ReadLine()); 10 string str = Convert.ToString(a, 2); 11 int c = 0; 12 foreach (char ch in str) 13 { 14 if (ch == '1') 15 { 16 c++; 17 } 18 } 19 Console.WriteLine(c); 20 Console.ReadKey(); 21 } 22 } 23 }
9.
输入为一个整数n
输出一个整数,即第n项的值
4
3
1 public static void Main(string[] args) 2 { 3 int n = Convert.ToInt32(Console.ReadLine()); 4 int i=0; 5 for(;;i++) 6 { 7 if(n<=i*(i+1)/2&&n>(i-1)*i/2) 8 { 9 Console.WriteLine(i); 10 break; 11 } 12 } 13 }
10.