P1000
- import java.util.Scanner;
- public class Exercise1000 {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- while(sc.hasNext())
- {
- System.out.println(sc.nextInt()+sc.nextInt());
- }
- }
- }
P1001
- import java.util.Scanner;
- public class Exercise1001 {
- public static void main(String[] args) {
- int[][] a;
- int[][] b;
- int[][] c;
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- int row = sc.nextInt();
- if (row == 0)
- break;
- int col = sc.nextInt();
- a = new int[row][col];
- b = new int[row][col];
- c = new int[row][col];
- for (int i = 0; i < row; i++)
- for (int j = 0; j < col; j++)
- a[i][j] = sc.nextInt();
- for (int i = 0; i < row; i++)
- for (int j = 0; j < col; j++)
- b[i][j] = sc.nextInt();
- for (int i = 0; i < row; i++)
- for (int j = 0; j < col; j++)
- c[i][j] = a[i][j] + b[i][j];
- int sum = 0;
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- if (c[i][j] != 0)
- break;
- if (j == col - 1)//特别注意
- sum++;
- }
- }
- for (int j = 0; j < col; j++) {
- for (int i = 0; i < row; i++) {
- if (c[i][j] != 0)
- break;
- if (i == row - 1)
- sum++;
- }
- }
- System.out.println(sum);
- }
- }
- }
P1002
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Exercise1002 {
public static void main(String[] args) {
Scanner sc =new Scanner(new BufferedInputStream(System.in));
while(sc.hasNext())
{
double p=sc.nextDouble();
double t=sc.nextDouble();
double G1 = sc.nextDouble();
double G2 = sc.nextDouble();
double G3=sc.nextDouble();
double GJ=sc.nextDouble();
double grade=0;
if(Math.abs(G1-G2)<=t)
grade=(G1+G2)/2;
else if((Math.abs(G1-G3)<=t&&Math.abs(G2-G3)>t)||(Math.abs(G1-G3)>t&&Math.abs(G2-G3)<=t))
grade=((Math.abs(G1-G3)>Math.abs(G3-G2)?G2:G1)+G3)/2;
else if(Math.abs(G1-G3)<=t&&Math.abs(G2-G3)<=t)
grade=(G1>G2?G1:G2)>G3?(G1>G2?G1:G2):G3;
else if(Math.abs(G1-G3)>t && Math.abs(G2-G3)>t)
grade=GJ;
System.out.printf("%.1f", grade);
System.out.println();
}
}
}
P1003
- import java.math.BigInteger;
- import java.util.Scanner;
- public class Exercise1003_2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- String[] a = sc.next().split(",");
- String[] b = sc.next().split(",");
- System.out.println(big(a).add(big(b)));
- }
- }
- private static BigInteger big(String[] a) {
- String sa = "";
- for (String s : a)
- sa += s;
- return new BigInteger(sa);
- }
- }
如果模拟数组实现,一位一位做
P1004
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Exercise1004 {
public static void main(String[] args)
{
Scanner sc =new Scanner(new BufferedInputStream(System.in));
while(sc.hasNext())
{
ArrayList<Integer> arr=new ArrayList<Integer>();
int m=sc.nextInt();
for(int i=0;i<m;i++)
arr.add(sc.nextInt());
int n=sc.nextInt();
for(int i=0;i<n;i++)
arr.add(sc.nextInt());
Collections.sort(arr);
System.out.println(arr.get((m+n-1)/2));
}
}
}
排序解
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Exercise1004_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
while (sc.hasNext()) {
int m = sc.nextInt();
int[] a = new int[m];
for (int i = 0; i < m; i++)
a[i] = sc.nextInt();
int n = sc.nextInt();
int[] b = new int[m + n];
for (int i = 0; i < m; i++)
b[i] = a[i];
for (int i = m; i < m + n; i++)
b[i] = sc.nextInt();
System.out.println(select(b, (m + n - 1) / 2));
}
}
public static int select(int[] a, int k) {
int lo = 0, hi = a.length - 1;
while (lo < hi) {
int j = partition(a, lo, hi);
if (j == k)
return a[k];
else if (j < k)
lo = j + 1;
else if (j > k)
hi = j - 1;
}
return a[k];
}
public static int partition(int[] a, int lo, int hi) {
int i = lo, j = hi + 1;
while (true) {
while (a[++i] < a[lo])
if (i == hi)
break;
while (a[lo] < a[--j])
if (j == lo)
break;
if (i >= j)
break;
exch(a, i, j);
}
exch(a, lo, j);
return j;
}
public static void exch(int[] a, int i, int j) {
a[i] ^= a[j];
a[j] ^= a[i];
a[i] ^= a[j];
}
}
利用快排求中位数(平台过不了异或操作,可以用变量交换)
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Exercise1004_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
while (sc.hasNext()) {
int m = sc.nextInt();
int[] a = new int[m];
for (int i = 0; i < m; i++)
a[i] = sc.nextInt();
int n = sc.nextInt();
int[] b = new int[n];
for (int i = 0; i < n; i++)
b[i] = sc.nextInt();
int[] c = new int[m + n];
int i = 0, j = 0, k = 0;
while (i != m && j != n) {
if (a[i] > b[j])
c[k++] = b[j++];
else
c[k++] = a[i++];
}
while (k < m + n) {
if (i == m)
while (j != n)
c[k++] = b[j++];
else
while (i != m)
c[k++] = a[i++];
}
System.out.println(c[(m + n - 1) / 2]);
}
}
}
直接归并
P1008
- package Exercise1008;
- import java.io.BufferedInputStream;
- import java.util.LinkedList;
- import java.util.Scanner;
- public class Exercise_2 {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(new BufferedInputStream(System.in));
- while(sc.hasNext())
- {
- int n=sc.nextInt();
- int m=sc.nextInt();
- if(m==0&&n==0)
- System.exit(0);
- Vertex[] a=new Vertex[n+1];
- for(int i=1;i<=n;i++)
- a[i] =new Vertex(i,Double.MAX_VALUE,Double.MAX_VALUE);
- double[] edgeDis =new double[n+1];
- double[] edgePri =new double[n+1];
- for(int i=0;i<m;i++)
- {
- int v=sc.nextInt();
- int w=sc.nextInt();
- int d=sc.nextInt();
- int p=sc.nextInt();
- a[v].adj.add(new Edge1(w,d,p));
- a[w].adj.add(new Edge1(v,d,p));
- }
- IndexMinPQ<Vertex> pq=new IndexMinPQ<Vertex>(n);
- int s=sc.nextInt();
- int t =sc.nextInt();
- a[s].dist=0.0;
- a[s].price=0.0;
- pq.add(s, a[s]);
- while(!pq.isEmpty()&&!a[t].marked)
- {
- int v = pq.delMin();
- a[v].marked=true;
- for(Edge1 e:a[v].adj)
- {
- int w=e.otherVer;
- if(a[w].marked)
- continue;
- if((a[w].dist>a[v].dist+e.edgeDis)||(a[w].dist==a[v].dist+e.edgeDis&&a[w].price>a[v].price+e.edgePri))
- {
- a[w].dist=a[v].dist+e.edgeDis;
- a[w].price=a[v].price+e.edgePri;
- }
- if(pq.contains(w))
- pq.change(w,a[w]);
- else
- pq.add(w, a[w]);
- }
- }
- System.out.println((int)a[t].dist+" "+(int)a[t].price);
- }
- }
- }
- class Edge1{
- public int otherVer;
- public double edgeDis;
- public double edgePri;
- public Edge1(int otherVer,double edgeDis,double edgePri)
- {
- this.otherVer = otherVer;
- this.edgeDis = edgeDis;
- this.edgePri =edgePri;
- }
- }
- class Vertex implements Comparable<Vertex>{
- public double dist;
- public double price;
- public LinkedList<Edge1> adj ;
- public int topNum;
- public boolean marked;
- public Vertex(int topNum,double dist,double price)
- {
- this.topNum=topNum;
- this.dist =dist;
- this.price =price;
- adj =new LinkedList<Edge1>();
- marked=false;
- }
- @Override
- public int compareTo(Vertex v) {
- if(this.dist>v.dist)
- return 1;
- else if(this.dist <v.dist)
- return -1;
- else if(this.price>v.price)
- return 1;
- else if(this.price<v.price)
- return -1;
- return 0;
- }
- }
- class IndexMinPQ <E extends Comparable<E>>{
- private int N;
- private int[] pq;
- private int[] qp;
- private E[] keys;
- public IndexMinPQ(int maxN)
- {
- keys = (E[]) new Comparable[maxN+1];
- pq= new int[maxN+1];
- qp=new int[maxN+1];
- for(int i=0;i<=maxN;i++)
- qp[i] =-1;
- }
- //插入元素
- public void add(int k,E e)
- {
- N++;
- pq[N]=k;
- keys[k] =e;
- qp[k] =N;
- swim(N);
- }
- public void change(int k,E e)
- {
- keys[k] =e;
- swim(qp[k]);
- sink(qp[k]);
- }
- public boolean contains(int k)
- {
- return qp[k]!=-1;
- }
- public int delMin()
- {
- int indexOfMin=pq[1];
- exch(1,N--);//如果不先减小N,则元素会沉到N
- sink(1);
- keys[pq[N+1]]=null;//help GC
- qp[pq[N+1]]=-1;
- return indexOfMin;
- }
- public boolean isEmpty()
- {
- return N==0;
- }
- private boolean less(int i,int j)
- {
- return keys[pq[i]].compareTo(keys[pq[j]])<0;
- }
- private void exch(int i,int j)
- {
- int temp=pq[i];
- pq[i]=pq[j];
- pq[j] =temp;
- qp[pq[i]] =i;
- qp[pq[j]] =j;
- }
- private void swim(int k)
- {
- while(k>1&&less(k,k/2))
- {
- exch(k/2,k);
- k=k/2;
- }
- }
- private void sink(int k)
- {
- while(2*k<=N)
- {
- int j=2*k;
- while(j<N&&less(j+1,j))
- j++;
- if(less(k,j))
- break;
- exch(k,j);
- k=j;
- }
- }
- public E min()
- {
- return keys[pq[1]];
- }
- public int size()
- {
- return N;
- }
- }
prim算法+索引优先队列
P1009
- import java.util.Scanner;
- public class Exercise1009 {
- // public static void main(String[] args) {
- // Scanner sc = new Scanner(System.in);
- // int n;
- // while ((n = Integer.parseInt(sc.nextLine())) != 0) {
- //
- // String s = sc.nextLine();
- //
- // for (int i = 0; i < n; i++) {
- // String a = sc.nextLine();
- //
- // if (isSameTree(s, a))
- // System.out.println("Yes");
- // else
- // System.out.println("NO");
- //
- // }
- // }
- // }
- //
- // private static boolean isSameTree(String s, String a) {
- // if (s.equals(a))
- // return true;
- //
- // char[] chars = s.toCharArray();
- // char[] chara = a.toCharArray();
- //
- // if (s.length() != a.length() || chars[0] != chara[0]) {
- // return false;
- // } else {
- //
- // String[] subTrees = subTree(s);
- // String[] subTreea = subTree(a);
- //
- // return isSameTree(subTrees[0], subTreea[0])
- // && isSameTree(subTrees[1], subTreea[1]);
- // }
- // }
- //
- // private static String[] subTree(String str) {
- // String[] a = { "", "" };
- // for (int i = 1; i < str.length(); i++) {
- // char j = str.charAt(i);
- // if (j > str.charAt(0))
- // a[0] += j;
- // else
- // a[1] += j;
- //
- // }
- // return a;
- // }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n;
- while ((n = Integer.parseInt(sc.nextLine())) != 0) {
- String s = sc.nextLine();
- int[] s1 = creatTree(s);
- for (int i = 0; i < n; i++) {
- boolean flag = true;
- String a = sc.nextLine();
- int[] a1 = creatTree(a);
- for (int j = 1; j < s1.length; j++)
- if (s1[j] != a1[j]) {
- flag = false;
- break;
- }
- if (flag)
- System.out.println("YES");
- else
- System.out.println("NO");
- }
- }
- }
- private static int[] creatTree(String s) {
- int[] a = new int[1025];
- for (int i = 0; i < a.length; i++)
- a[i] = -1;
- a[1] = Integer.parseInt(s.charAt(0) + "");
- for (int i = 1; i < s.length(); i++) {
- int k = Integer.parseInt(s.charAt(i) + "");
- int j = 1;
- while (a[j] != -1) {
- if (k > a[j])
- j = j * 2 + 1;
- else
- j = j * 2;
- }
- a[j] = k;
- }
- return a;
- }
- }
第一种方法为什么错未知,第二种没有构造二叉树,用了静态数组
注意flag定义的位置,如果定义在while外面,记得加else
P1010
- import java.util.Hashtable;
- import java.util.Scanner;
- public class Exercise1010 {
- Hashtable<String, String> ht;
- public Exercise1010() {
- ht = new Hashtable<String, String>();
- ht.put("zero", "0");
- ht.put("one", "1");
- ht.put("two", "2");
- ht.put("three", "3");
- ht.put("four", "4");
- ht.put("five", "5");
- ht.put("six", "6");
- ht.put("seven", "7");
- ht.put("eight", "8");
- ht.put("nine", "9");
- }
- public static void main(String[] args) {
- Exercise1010 ex = new Exercise1010();
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- String str = sc.nextLine();
- int j = str.indexOf('+');
- int k = str.indexOf('=');
- String[] sub1 = str.substring(0, j).split(" ");
- String[] sub2 = str.substring(j + 2, k).split(" ");
- int sum = ex.value(sub1) + ex.value(sub2);
- if (sum == 0)
- System.exit(0);
- System.out.println(ex.value(sub1) + ex.value(sub2));
- }
- }
- private int value(String[] sub) {
- String str = "";
- for (String s : sub)
- str += this.ht.get(s);
- return Integer.parseInt(str);
- }
- }
P1011
import java.util.Scanner;
public class Exercise1011 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int k = sc.nextInt();
if (k == 0)
System.exit(0);
int[] a = new int[k];
for (int i = 0; i < k; i++)
a[i] = sc.nextInt();
int sum = 0;
int b = 0;
int lo = 0;
int lob = 0;
int hi = 0;
boolean flag = false;
for (int i = 0; i < k; i++) {
if (a[i] >= 0)
flag = true;
if (b > 0) {
b += a[i];
} else {
b = a[i];
lob = i;
}
if (sum <= b) {
sum = b;
hi = i;
lo = lob;
}
}
if (!flag) {
lo = 0;
hi = k - 1;
sum = 0;
}
while (a[hi] == 0 && hi >= 0 && sum > 0)
hi--;
System.out.println(sum + " " + a[lo] + " " + a[hi]);
}
}
}
动态规划解最大子序列
P1014
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- public class Exercise1014 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- int n = sc.nextInt();
- if (0 == n)
- System.exit(0);
- int m = sc.nextInt();
- int g = sc.nextInt();
- int[] score = new int[m + 1];
- int count = 0;
- score[0] = 0;
- for (int i = 1; i <= m; i++)
- score[i] = sc.nextInt();
- sc.nextLine();
- ArrayList<Student> arr = new ArrayList<Student>();
- for (int i = 0; i < n; i++) {
- String[] s = sc.nextLine().split(" ");
- int sum = 0;
- for (int j = 2; j < s.length; j++)
- sum += score[Integer.parseInt(s[j])];
- if (sum >= g) {
- count++;
- Student student = new Student(s[0], sum);
- arr.add(student);
- }
- }
- Collections.sort(arr);
- System.out.println(count);
- for (Student student : arr)
- System.out.println(student);
- }
- }
- }
- class Student implements Comparable {
- private String id;
- private int score;
- public Student(String id, int score) {
- this.id = id;
- this.score = score;
- }
- @Override
- public int compareTo(Object o) {
- Student t = (Student) o;
- if (this.score < t.score)
- return 1;
- else if (this.score > t.score)
- return -1;
- else
- return this.id.compareTo(t.id);
- }
- public String toString() {
- return this.id + " " + this.score;
- }
- }
注意nextInt后调用nextLine,要先跳过本行
注意重写compareTo方法
P1016
- import java.util.Scanner;
- public class Exercise1016 {
- public static void main(String[] args)
- {
- int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
- Scanner sc=new Scanner(System.in);
- while(sc.hasNext())
- {
- String input1=sc.next();
- String input2=sc.next();
- if("0".equals(input1)&&"0".equals(input2))
- System.exit(0);
- int[] a=str(input1.split(","));
- int[] b=str(input2.split(","));
- int[] c=new int[26];
- for(int i=0;i<25;i++)
- {
- c[i]+=a[i]+b[i];
- if(c[i]>=prime[i])
- {
- c[i+1]=c[i]/prime[i];
- c[i]=c[i]%prime[i];
- }
- }
- boolean flag=false;
- for(int i=25;i>0;i--)
- {
- if(c[i]!=0)
- flag=true;
- if(flag)
- System.out.print(c[i]+",");
- }
- System.out.print(c[0]);
- System.out.println();
- }
- }
- public static int[] str(String[] s)
- {
- int[] str=new int[26];
- for(int i=0;i<s.length;i++)
- str[i]=Integer.parseInt(s[s.length-1-i]);
- return str;
- }
- }
P1020
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- public class Exercise1020 {
- public static void main(String[] args) {
- ArrayList xarr;
- ArrayList yarr;
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- int a = sc.nextInt();
- int b = sc.nextInt();
- if (a == 0 && b == 0)
- System.exit(0);
- xarr = new ArrayList();
- yarr = new ArrayList();
- xarr.add(a);
- yarr.add(b);
- while (true) {
- a = sc.nextInt();
- b = sc.nextInt();
- if (a == 0 && b == 0) {
- Collections.sort(xarr);
- Collections.sort(yarr);
- System.out.println(xarr.get(0) + " " + yarr.get(0) + " "
- + xarr.get(xarr.size() - 1) + " "
- + yarr.get(yarr.size() - 1));
- break;
- }
- xarr.add(a);
- yarr.add(b);
- }
- }
- }
- }
P1034
- import java.util.ArrayDeque;
- import java.util.Deque;
- import java.util.PriorityQueue;
- import java.util.Scanner;
- public class Exercise1034 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- int n = sc.nextInt();
- int m = sc.nextInt();
- if (n == 0 && m == 0)
- System.exit(0);
- int j;
- PriorityQueue<Integer> pq = new PriorityQueue<Integer>(m);
- for (int i = 0; i < n; i++) {
- j = sc.nextInt();
- if (pq.size() < m)
- pq.offer(j);
- else
- if (j > pq.peek()) {
- pq.poll();
- pq.offer(j);
- }
- }
- Deque<Integer> a = new ArrayDeque<Integer>();
- while (!pq.isEmpty())
- a.push(pq.poll());
- while (a.size() > 1)
- System.out.print(a.pop() + " ");
- System.out.println(a.pop());
- }
- }
- }
求最大m个,用小顶堆。
如果要大顶堆,则需要构造比较器,代码如下
- //固定容量的优先队列,模拟大顶堆,用于解决求topN小的问题
- public static class FixSizedPriorityQueue>{
- private PriorityQueue queue;
- private int maxSize; //堆的最大容量
- public FixSizedPriorityQueue(int maxSize){
- if(maxSize <= 0) throw new IllegalArgumentException();
- this.maxSize = maxSize;
- this.queue = new PriorityQueue(maxSize, new Comparator() {
- @Override
- public int compare(E o1, E o2) {
- return o2.compareTo(o1);
- }
- });
- }
- public void add(E e){
- if(queue.size() < maxSize){ //未达到最大容量,直接添加
- queue.add(e);
- }else{ //队列已满
- E peek = queue.peek();
- if(e.compareTo(peek) < 0){ //将新元素与当前堆顶元素比较,保留较小的元素
- queue.poll();
- queue.add(e);
- }
- }
- }
- public List sortedList(){
- List list = new ArrayList(queue);
- Collections.sort(list); //PriorityQueue本身的遍历是无序的,最终需要对队列中的元素进行排序
- return list;
- }
- }
P1045
- import java.util.Scanner;
- <span style="white-space:pre"> </span>public static void main(String[] args) {
- <span style="white-space:pre"> </span>Scanner sc = new Scanner(System.in);
- <span style="white-space:pre"> </span>double n;
- <span style="white-space:pre"> </span>while (sc.hasNext()) {
- <span style="white-space:pre"> </span>n = sc.nextDouble();
- <span style="white-space:pre"> </span>for (int x = 0; x <= n / 5; x++)
- <span style="white-space:pre"> </span>for (int y = 0; y <= n / 3; y++) {
- <span style="white-space:pre"> </span>int z = 100 - y - x;
- <span style="white-space:pre"> </span>if (5 * x + 3 * y + z / 3.0 <= n)
- <span style="white-space:pre"> </span>System.out.println("x=" + x + ",y=" + y + ",z=" + z);
- <span style="white-space:pre"> </span>}
- <span style="white-space:pre"> </span>}
- <span style="white-space:pre"> </span>}
- }
1.注意输入描述中的“ 测试数据有多组 ”
2.注意当n被定义为整形时n/3将自动舍弃小数部分
P1046
- import java.util.*;
- public class Exercise1046 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNextLine()) {
- String str = sc.nextLine();
- String[] a = str.split(" ");
- ArrayList arr = new ArrayList();
- for (int i = 0; i < a.length; i++)
- arr.add(Integer.parseInt(a[i]));
- Collections.sort(arr);
- System.out.println("max=" + arr.get(arr.size() - 1));
- }
- }
- }
简单题,懒得自己写找最大值。没要求实现泛型,就不写了
P1047
- import java.util.Scanner;
- public class Exercise1047 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- int n = sc.nextInt();
- if (isPrime(n))
- System.out.println("yes");
- else
- System.out.println("no");
- }
- }
- private static boolean isPrime(int n) {
- if (n < 2)
- return false;
- else if (n == 2)
- return true;
- else if ((n & 1) == 0)
- return false;
- else {
- int j = (int) Math.sqrt(n);
- for (int i = 3; i <= j; i = i + 2)
- if (n % i == 0)
- return false;
- return true;
- }
- }
- }
P1048
- import java.util.Scanner;
- public class Exercise1048 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()) {
- int a = sc.nextInt();
- int b = sc.nextInt();
- int c = sc.nextInt();
- if (a < b) {
- a ^= b;
- b ^= a;
- a ^= b;
- }
- if (a < c) {
- a ^= c;
- c ^= a;
- a ^= c;
- }
- if (foo(a, b, c) > 0)
- System.out.println("钝角三角形");
- else if (foo(a, b, c) == 0)
- System.out.println("直角三角形");
- else
- System.out.println("锐角三角形");
- }
- }
- private static int foo(int a, int b, int c) {
- return a * a - b * b - c * c;
- }
- }
题目明确指明三角形,就没做判断
P1049
- import java.util.Scanner;
- public class Exercise1049 {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- while(sc.hasNext())
- {
- String str = sc.nextLine();
- char c = sc.nextLine().charAt(0);
- char[] s = str.toCharArray();
- str="";
- for(int i=0;i<s.length;i++)
- {
- if(s[i]!=c)
- str += s[i];
- }
- System.out.println(str);
- }
- }
- }