codeforces 160A-C語言解題報告

160A題目網址

題目解析

1.輸入硬幣的個數,分配硬幣,使拿最小的硬幣數比剩下的硬幣金額大

舉例:
輸入:
2
3 3
輸出
2

2.注意點:
1)接收整型數組時要使用&,因為只有字符數組是使用指針傳遞首地址的
scanf("%d",&a[i]);

2)使用冒泡排序,將數組從大到小排序
for(int j=0;j<n-1;j++)
for(int k=0;k<n-1-j;k++)

3)使用count_all去計算所有的硬幣金額,使用count_now去計算現在拿的硬幣金額,再將它與剩下的硬幣金額比較

代碼

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{int n=0,count_all=0,count_now=0,count=0;scanf("%d",&n);int a[100]={0};for(int i=0;i<n;i++){//字符串才可以 char a[i],字符數組才使用了指針scanf("%d",&a[i]);//&count_all+=a[i];}for(int j=0;j<n-1;j++){for(int k=0;k<n-1-j;k++){if(a[k]<a[k+1]){int temp=0;temp=a[k];a[k]=a[k+1];a[k+1]=temp;}}}for(int m=0;m<n;m++){count_now+=a[m];count++;if(count_now>(count_all-count_now)){break;}}printf("%d",count);getchar();system("pause");return 0;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/446645.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/446645.shtml
英文地址,請注明出處:http://en.pswp.cn/news/446645.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

英語口語-文章朗讀Week10 Monday

英語文章 Here are some valuable suggestions which may assist you in landing good job First, make your resume clear and associate it with the position you are applying for. Try to add details like your temporary jobs at college or your former jobs Second, …

論文遇到的格式問題和修正方式

word空格出現小圓點怎么辦論文參考文獻批量改為上角標&#xff0c;簡單好用&#xff01;&#xff01;&#xff01;字數統計網站word封面下劃線怎么對齊&#xff08;非常簡單徹底解決&#xff09;

codeforces 41A-C語言解題報告

41A題目網址 題目解析 1.輸入一個字符串,如果第二行是倒序輸入這個字符串的,就輸出YES,否則輸出NO 舉例: 輸入: abb aba 輸出: NO 2.倒序輸出時,使用int jstrlen(t)-1;,因為strlen()是計算字符個數,而字符串是從0開始,最后一位是字符串長度減一 3.在接收第二個字符串輸入時…

Linux查看文件的首個字母 文件屬性字段

-rw-r–r– 1 root root 762 07-29 18:19 exit文件屬性字段總共有10個字母組成&#xff1b;第一個字符代表文件的類型。 文件屬性字段 字母“-”表示該文件是一個普通文件字母“d”表示該文件是一個目錄&#xff0c;字母”d”&#xff0c;是dirtectory(目錄)的縮寫&#xff1b…

英語口語-文章朗讀Week10 Wednesday

英語文章 Everyone needs sleep for survival, but how much? It is said that eight hours of sleep is fundamental to a healthy person. But today, many people are sacrificing their sleep time。 Modern people have so many alternatives: cell phones, PCs, TVs, g…

嵌入式Linux多任務編程 進程 管道 命名管道

進程 進程是一個可并發執行的具有獨立功能的程序關于某個數據集合的一次執行過程&#xff0c;也是操作系統執行資源分配和保護的基本單位。程序的一次執行就是一個進程一個程序可以派生多個進程多個不同程序運行的時候&#xff0c;也會有多個相對應的進程與其相互對應進程是動…

2000年考研英語閱讀理解文章五

文章詳細解析網址 知識點 ----單詞 vitality n生命力 hypocritical adj偽善的 pushing adj有進取心的 acquisitive adj渴望獲得的,貪得無厭的 confess v供認,坦白 vulgar adj粗俗的 spectacle n場面,奇觀 participatory adj供分享的 democracy n民主,民主制,民主國家 stir v攪…

英語口語-文章朗讀Week10 Thursday

英語文章 There are many customs and traditions in Chinese civilization. Here, we will talk about the development of the way people greet each other: In ancient times, people had to kneel to those who were superior to them. This custom remained until the …

Linux進程之間通信 信號

2) SIGINT 程序終止(interrupt)信號, 在用戶鍵入INTR字符(通常是Ctrl-C)時發出&#xff0c;用于通知前臺進程組終止進程。 3) SIGQUIT 和SIGINT類似, 但由QUIT字符(通常是Ctrl-\)來控制. 進程在因收到SIGQUIT退出時會產生core文件, 在這個意義上類似于一個程序錯誤信號。 15)…

c++面向對象高級編程 學習一 不帶指針的類

復數類 complex 是一個不帶指針的類&#xff0c;其聲明如下&#xff1a; class complex { public: complex(double r0,double i0):re(r),im(i){} complex& operator (const complex&); double real()const{return re;} double imag()const{return im;}private: double…

codeforces 734A-C語言解題報告

734A題目網址 題目解析 1.輸入n個結果,再輸入每一個結果(A或D),統計A和D的數目,A>D,則輸出Anton,A<D,輸出Danik,AD,輸出Friendship 代碼 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { int n0,A0…

Linux進程之間通信 消息隊列

使用命令 ipcs -q 查看對應的消息隊列代碼 文件接收者 #include <sys/types.h> #include <stdio.h> #include <unistd.h> #include <string> #include <signal.h> #include <wait.h> #include <sys/msg.h> #include <cstring&g…

c++面向對象高級編程 學習二 帶指針的類

帶指針的類&#xff0c;必須要自己寫拷貝構造和賦值構造 拷貝構造&#xff1a;參數和類的類型一樣的構造函數 賦值構造&#xff1a;重寫操作符&#xff0c;且其參數和類的類型一樣 class String { public: String(const char* cstr 0); String(const String& str); Strin…

英語口語 week11 Tuesday

英語文章 It was a cold and gloomy winter afternoon, people with their chilled hands tucked into their pockets or hidden in their sleeves. Fred was in a depressed mood, just like the weather,for he failed to get any award in the debate competition When he …

codeforces 271A-C語言解題報告

271A題目網址 題目解析 1.輸入一個年份,求這個年份之后的每一個數字都各不相同的年份 舉例: 輸入: 2013 輸出: 2014 2.求年份(四位數)的每一位數,再把這些數逐個比較 四位數求: 千位:n/1000 百位:n%1000/100 十位:n%100/10 個位:n%10/1; 代碼 #include<stdio.h> #in…

進程之間通信 共享內存

命令 ipcs 命令查看共享內存、消息隊列、管道等相關信息ipcs -m 查看共享內存的信息代碼 創建共享內存共享內存 關聯 進程分離共享內存刪除共享內存 #include <sys/shm.h> #include <iostream>#define BUF_SIZE 1024int main() {int share_id 0;//創建共享內存i…

c++面向對象高級編程 學習三 堆、棧和內存泄漏

棧&#xff0c;是存在于某作用域的一塊內存空間。在函數體內聲明的任何變量&#xff0c;其所使用的內存空間均來自于棧。 堆&#xff0c;是指由操作系統提供的一塊global內存空間&#xff0c;程序可動態分配獲得若干內存空間塊。 new操作符生成的對象所占用的內存空間即是從堆中…

clion編寫C++ 使用多線程時候,CMakeLists.txt書寫,引用-pthread

添加如下一行 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") 具體的例子 cmake_minimum_required(VERSION 3.17) project(mutex_learn)set(CMAKE_CXX_STANDARD 14)set(BOOST_ROOT "/usr/local/include/boost") #添加頭文件搜索路徑 include_direc…

codeforces 677A-C語言解題報告

677A題目網址 題目解析 1.輸入n個數字,如果輸入的數字比h大,就加2,如果小于等于h,就加1 舉例: 輸入: 3 7 4 5 14 輸出: 4 代碼 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { int n0,h0,count0;int nu…