public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a=n/100; int b=n/10%10; int c=n%10; if(n==a*a*a+b*b*b+c*c*c) System.out.println("YES"); else System.out.println("NO"); } }
public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int T=sc.nextInt(); System.out.println(f(n,k,T)); }
private static String f(int n, int k, int t) { int shu=1; int conut=0; int sum=0; for (int i = 0; i < t; i++) { for (int j = 0; j < n; j++) { shu+=conut; conut++; while(shu>k-1){ shu=shu-k; } if(j==0) sum+=shu; } } return sum+""; } }
public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int k=sc.nextInt(); int t=sc.nextInt(); long sum=1,l=1,r=n,x=1; for (int i = 1; i < t; i++) { x+=(l+r)*n/2; x=x%k; sum+=x; l=1+i*n; r=n+i*n; } System.out.println(sum); } } }
public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=Integer.parseInt(sc.next()); String s=sc.next(); switch (n) { case 1: System.out.println(s.toUpperCase()); break; case 2: System.out.println(s.toLowerCase()); break; case 3: for (int i = s.length()-1; i >= 0; i--) { System.out.print(s.charAt(i)); } break; case 4: for (int i = 0; i < s.length(); i++) { if(s.charAt(i)>=97&&s.charAt(i)<=122){ System.out.print((char)(s.charAt(i)-32)); }else if(s.charAt(i)>=65&&s.charAt(i)<=90){ System.out.print((char)(s.charAt(i)+32)); } } break; case 5: s=s.toLowerCase(); String re=s.charAt(0)+""; char a=s.charAt(0); int count=0; if(s.length()==2){ System.out.println(s); return; } for (int i = 1; i < s.length(); i++) { if(s.charAt(i)-a==1){ count++; }else{ if(count>1){ re+="-"; re+=s.charAt(i-1); } re+=s.charAt(i); count=0; } a=s.charAt(i); } if(count>1){ re+="-"; re+=s.charAt(s.length()-1); } if(count==1){ re+=s.charAt(s.length()-1); } System.out.println(re); break; } } } }
算法训练 P1102 时间限制:1.0s 内存限制:256.0MB
定义一个学生结构体类型student,包括4个字段,姓名、性别、年龄和成绩。然后在主函数中定义一个结构体数组(长度不超过1000),并输入每个元素的值,程序使用冒泡排序法将学生按照成绩从小到大的顺序排序,然后输出排序的结果。 输入格式:第一行是一个整数N(N<1000),表示元素个数;接下来N行每行描述一个元素,姓名、性别都是长度不超过20的字符串,年龄和成绩都是整型。 输出格式:按成绩从小到大输出所有元素,若多个学生成绩相同则成绩相同的同学之间保留原来的输入顺序。 输入: 3 Alice female 18 98 Bob male 19 90 Miller male 17 92
输出: Bob male 19 90 Miller male 17 92 Alice female 18 98