7-5 找最長的字串 (15 分)
本題要求編寫程式,針對輸入的N個字串,輸出其中最長的字串。
輸入格式:
輸入第一行給出正整數N;隨後N行,每行給出一個長度小於80的非空字串,其中不會出現換行符,空格,製表符。
輸出格式:
在一行中用以下格式輸出最長的字串:
The longest is: 最長的字串
如果字串的長度相同,則輸出先輸入的字串。
輸入樣例:
5
li
wang
zhang
jin
xiang
輸出樣例:
The longest is: zhang
#include<stdio.h> #include<string.h> #define MAX 100 int main() { int n; char s1[MAX],s2[MAX]; scanf("%d",&n); gets(s1); strcpy(s2,s1); for(int i=0;i<n;i++) { gets(s1); if(strlen(s1)>strlen(s2)) strcpy(s2,s1); } printf("The longest is: %s",s2); return 0; }
相關推薦
7-5 輸出整數各位數字(15 分)
一、題目 二、個人理解 此題估計出題人是想我們不斷地進行取位數來做,但是實際上我們直接用字串輸入,再輸出即可。 C語言: #include <stdio.h> #in
7-5 找最長的字串 (15 分)
本題要求編寫程式,針對輸入的N個字串,輸出其中最長的字串。 輸入格式: 輸入第一行給出正整數N;隨後N行,每行給出一個長度小於80的非空字串,其中不會出現換行符,空格,製表符。 輸出格式: 在一行中用以下格式輸出最長的字串: The longest is: 最長的字串 如
7-4 找最小的字串 (15 分)
本題要求編寫程式,針對輸入的N個字串,輸出其中最小的字串。 輸入格式: 輸入第一行給出正整數N;隨後N行,每行給出一個長度小於80的非空字串,其中不會出現換行符,空格,製表符。 輸出格式: 在一行中用以下格式輸出最小的字串: Min is: 最小字串 輸入樣例: 5
7-5 交換最小值和最大值(15 分)
7-5 交換最小值和最大值(15 分) 本題要求編寫程式,先將輸入的一系列整數中的最小值與第一個數交換,然後將最大值與最後一個數交換,最後輸出交換後的序列。 注意:題目保證最大和最小值都是唯一
7-26 最大公約數和最小公倍數 (15 分)
本題要求兩個給定正整數的最大公約數和最小公倍數。 輸入格式: 輸入在一行中給出兩個正整數M和N(≤1000)。 輸出格式: 在一行中順序輸出M和N的最大公約數和最小公倍數,兩數字間以1空格分隔。 輸入樣例: 511 292 輸出樣例: 73 2044 鳴謝
7-6 最大公約數和最小公倍數(15 分)
7-6 最大公約數和最小公倍數(15 分) 本題要求兩個給定正整數的最大公約數和最小公倍數。 輸入格式: 輸入在一行中給出兩個正整數M和N(≤1000)。 輸出格式: 在一行中順序輸出M和
7-13 最大公約數和最小公倍數(15 分)
本題要求兩個給定正整數的最大公約數和最小公倍數。 輸入格式: 輸入在一行中給出兩個正整數M和N(≤1000)。 輸出格式: 在一行中順序輸出M和N的最大公約數和最小公倍數,兩數字間以1空格分隔。 輸入樣例: 511 292 輸出樣例: 73 2044 #include<stdio.h&g
7-26 最大公約數和最小公倍數(15 分)
題目: 本題要求兩個給定正整數的最大公約數和最小公倍數。 輸入格式: 輸入在一行中給出兩個正整數M和N(≤1000)。 輸出格式: 在一行中順序輸出M和N的最大公約數和最小公倍數,兩數字間以1空格分隔。 輸入樣例: 511 292 輸出樣例:
基礎程式設計題目集 - 7-1 釐米換算英尺英寸(15 分)
題目連結:點選開啟連結 題目大意:略。 解題思路:注意:最後一句話的內涵,意味著 inch/12 是 foot 的小數部分。 AC 程式碼 [cpp]
PTA程式設計練習:7-2 然後是幾點(15 分)
題目: 有時候人們用四位數字表示一個時間,比如1106表示11點零6分。現在,你的程式要根據起始時間和流逝的時間計算出終止時間。 讀入兩個數字,第一個數字以這樣的四位數字表示當前時間,第二個數字表示分鐘數,計算當前時間經過那麼多分鐘後是幾點,結果也表
7-5 還原二叉樹 (25 分)(二叉樹,根據 中序遍歷 和 先序遍歷)
7-5 還原二叉樹 (25 分) 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。 輸入格式: 輸入首先給出正整數N(≤50),為樹中結點總數。下面兩行先後給出先序和中序遍歷序列,均是長度為N的不包含重複英文字母(區別大小寫)的字串。 輸出格式:
PTA天梯賽練習集 L1-050 倒數第N個字串 (15 分)
給定一個完全由小寫英文字母組成的字串等差遞增序列,該序列中的每個字串的長度固定為 L,從 L 個 a 開始,以 1 為步長遞增。例如當 L 為 3 時,序列為 { aaa, aab, aac, …, aaz, aba, abb, …, abz, …, zzz }
7-37 輸出整數各位數字 (15 分)
本題要求編寫程式,對輸入的一個整數,從高位開始逐位分割並輸出它的各位數字。 輸入格式: 輸入在一行中給出一個長整型範圍內的非負整數。 輸出格式: 從高位開始逐位輸出該整數的各位數字,每個數字後面有一個空格。 輸入樣例: 123456 輸出樣例: 1 2 3 4
7-35 猴子吃桃問題 (15 分)
一隻猴子第一天摘下若干個桃子,當即吃了一半,還不過癮,又多吃了一個;第二天早上又將剩下的桃子吃掉一半,又多吃了一個。以後每天早上都吃了前一天剩下的一半加一個。到第N天早上想再吃時,見只剩下一個桃子了。問:第一天共摘了多少個桃子? 輸入格式: 輸入在一行中給出正整數N(1<N≤10)
浙大版《C語言程式設計(第3版)》題目集 - 習題11-5 指定位置輸出字串(20 分)
題目連結:點選開啟連結 題目大意:略。 解題思路:略。 AC 程式碼 char *match( char *s, char ch1, char ch2 ) { char *p=s, *h; int fst=1,
7-5 樹的同構(25 分)
給定兩棵樹T1和T2。如果T1可以通過若干次左右孩子互換就變成T2,則我們稱兩棵樹是“同構”的。例如圖1給出的兩棵樹就是同構的,因為我們把其中一棵樹的結點A、B、G的左右孩子互換後,就得到另外一棵樹。而圖2就不是同構的。 圖1 圖2 現給定兩棵樹,請你判斷它們是否
習題7-3 判斷上三角矩陣 (15 分)
上三角矩陣指主對角線以下的元素都為0的矩陣;主對角線為從矩陣的左上角至右下角的連線。 本題要求編寫程式,判斷一個給定的方陣是否上三角矩陣。 輸入格式: 輸入第一行給出一個正整數T,為待測矩陣的個數。接下來給出T個矩陣的資訊:每個矩陣資訊的第一行給出一個不超過10的正整數n。隨後n行,
7-11 爬動的蠕蟲(15 分)
一條蠕蟲長1寸,在一口深為N寸的井的底部。已知蠕蟲每1分鐘可以向上爬U寸,但必須休息1分鐘才能接著往上爬。在休息的過程中,蠕蟲又下滑了D寸。就這樣,上爬和下滑重複進行。請問,蠕蟲需要多長時間才能爬出井? 這裡要求不足1分鐘按1分鐘計,並且假定只要在某次上爬過程中蠕蟲的頭部到達了井的頂部,那麼蠕蟲就完成任務了
PTA習題7-3 判斷上三角矩陣(15 分)
#include<stdio.h> int main() { int T,N,i,j,flag; scanf("%d",&T); while(T--){ scanf("%d",&N);
7-17 爬動的蠕蟲(15 分)
一條蠕蟲長1寸,在一口深為N寸的井的底部。已知蠕蟲每1分鐘可以向上爬U寸,但必須休息1分鐘才能接著往上爬。在休息的過程中,蠕蟲又下滑了D寸。就這樣,上爬和下滑重複進行。請問,蠕蟲需要多長時間才能爬出井? 這裡要求不足1分鐘按1分鐘計,並且假定只要在某次上爬過程中蠕蟲的頭