Hello World for U

import java.util.Scanner;
public class U{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String[] input = new String[1];
        input[0] = scan.nextLine();
        int i = 1;
        while(scan.hasNext()){
            input = enlargeArray(input);
            input[i] = scan.nextLine();
            i++;
        } 
        //System.out.println(input.length);
        for(int t=0;t<input.length;t++) 
                out(input[t]);      

    }

    //扩大数组算法
    public static String[] enlargeArray(String[] input){
        int length = input.length;
        String[] temp = new String[length+1];
        for(int i=0;i<length;i++)
            temp[i] = input[i];
        input = temp;
        return input;
    }

    public static void out(String input){
        int n1=0,n2=0,n3=0;
        int minresult = 0;
        int length = 0;
        length =input.length();
        //System.out.println(length);
        String[] n = new String[3];
        minresult = (length+2)/3;
        //System.out.print("minresult: "+minresult);
        if((length+2)%3==0)
            n1=n2=n3 = minresult;   
        else{
            n1=1;
            n2=2;
            n3=minresult+1;
            while(n1!=n2){
                n1 = (length+2-n3)/2;
                n2 = length+2-n1-n3;
                if(n1!=n2)
                    n3++;
            }
        }

        //System.out.println("n1: "+n1+" n2:"+n2+" n3:"+n3);
        n[0] = input.substring(0,n1-1);
        n[1] = input.substring(n1-1,n1+n3-1);
        n[2] = input.substring(n1+n3-1,n1+n2+n3-2);
        //System.out.println("n[0]: "+n[0]+" n[1]: "+n[1]+" n[2]: "+n[2]);
        int k = n[2].length()-1;
        for(int i=0;i<n[0].length();i++){
            System.out.print(n[0].charAt(i));
            for(int j=0;j<n3-2;j++)
                System.out.print(" ");
            System.out.println(n[2].charAt(k--));
        }
        System.out.println(n[1]);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Avahi-daemon 是一个开源的零配置网络系统,可以自动发现网络上的服务和设备。要连接另一台计算机主机的服务并发送 hello world,需要按照以下步骤进行操作: 1. 首先,确保两台计算机都已经安装了 Avahi-daemon。 2. 在第一台计算机上创建一个服务,例如使用 Python 的 Flask 框架创建一个 Web 服务,并将其注册到 Avahi-daemon 上,可以使用 Python 的 avahi-python 库来完成这个任务。 3. 在第二台计算机上使用 avahi-browse 命令来查找第一台计算机的服务,例如: ``` avahi-browse -a ``` 这个命令会列出所有可用的服务,可以找到第一台计算机的服务。 4. 使用 Avahi-daemon 提供的客户端库连接到第一台计算机的服务,并发送 hello world,可以使用 C 语言的 avahi-client 库来完成这个任务。 ``` #include <avahi-client/client.h> #include <avahi-client/lookup.h> #include <avahi-common/error.h> #include <avahi-common/thread-watch.h> #include <stdio.h> #include <stdlib.h> static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void *userdata) { if (event == AVAHI_RESOLVER_FOUND) { char addr[AVAHI_ADDRESS_STR_MAX]; avahi_address_snprint(addr, sizeof(addr), address); printf("Resolved '%s' on %s:%u, address is %s\n", name, host_name, port, addr); // Connect to the service and send hello world // ... } } static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *userdata) { AvahiClient *client = userdata; switch (event) { case AVAHI_BROWSER_NEW: avahi_service_resolver_new(client, interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, resolve_callback, NULL); break; } } int main(int argc, char **argv) { AvahiClient *client = NULL; int error; // Initialize the client client = avahi_client_new(avahi_threaded_poll_get(), 0, NULL, NULL, &error); if (!client) { fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); exit(1); } // Browse for services AvahiServiceBrowser *browser = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, client); if (!browser) { fprintf(stderr, "Failed to create browser: %s\n", avahi_strerror(error)); exit(1); } // Run the event loop avahi_threaded_poll_start(avahi_threaded_poll_get()); // Cleanup avahi_service_browser_free(browser); avahi_client_free(client); return 0; } ``` 这个程序会查找名为 "_http._tcp" 的服务,并连接到第一个找到的服务,如果成功连接到服务,会输出服务的名称、地址和端口号,并发送 hello world 消息。 以上就是使用 Avahi-daemon 连接另一台计算机主机的服务并发送 hello world 的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值